Skip to content

Extract the nanoseconds from a Duration type

Description

Extract the nanoseconds from a Duration type

Usage

<Expr>$dt$total_nanoseconds()

Value

A polars expression

Examples

library("polars")

df <- pl$select(date = pl$datetime_range(
  start = as.POSIXct("2020-1-1", tz = "GMT"),
  end = as.POSIXct("2020-1-1 00:00:01", tz = "GMT"),
  interval = "1ms"
))
df$with_columns(
  diff_nanosec = pl$col("date")$diff()$dt$total_nanoseconds()
)
#> shape: (1_001, 2)
#> ┌─────────────────────────────┬──────────────┐
#> │ date                        ┆ diff_nanosec │
#> │ ---                         ┆ ---          │
#> │ datetime[ms, GMT]           ┆ i64          │
#> ╞═════════════════════════════╪══════════════╡
#> │ 2020-01-01 00:00:00 GMT     ┆ null         │
#> │ 2020-01-01 00:00:00.001 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.002 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.003 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.004 GMT ┆ 1000000      │
#> │ …                           ┆ …            │
#> │ 2020-01-01 00:00:00.996 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.997 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.998 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:00.999 GMT ┆ 1000000      │
#> │ 2020-01-01 00:00:01 GMT     ┆ 1000000      │
#> └─────────────────────────────┴──────────────┘