Calculates the total number of nanoseconds for a duration column.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt64 expression with the total number of nanoseconds for a duration column |
Examples:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | >>> import datetime
>>> import daft
>>> from daft.functions import total_nanoseconds
>>> df = daft.from_pydict(
... {
... "duration": [
... datetime.timedelta(seconds=1),
... datetime.timedelta(milliseconds=1),
... datetime.timedelta(microseconds=1),
... datetime.timedelta(days=1),
... datetime.timedelta(hours=1),
... datetime.timedelta(minutes=1),
... ]
... }
... )
>>> df.with_column("Total Nanoseconds", total_nanoseconds(df["duration"])).show()
|
╭──────────────┬───────────────────╮
│ duration ┆ Total Nanoseconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═══════════════════╡
│ 1s ┆ 1000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 1000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 1000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60000000000 │
╰──────────────┴───────────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898 | def total_nanoseconds(expr: Expression) -> Expression:
"""Calculates the total number of nanoseconds for a duration column.
Returns:
Expression: a UInt64 expression with the total number of nanoseconds for a duration column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import total_nanoseconds
>>> df = daft.from_pydict(
... {
... "duration": [
... datetime.timedelta(seconds=1),
... datetime.timedelta(milliseconds=1),
... datetime.timedelta(microseconds=1),
... datetime.timedelta(days=1),
... datetime.timedelta(hours=1),
... datetime.timedelta(minutes=1),
... ]
... }
... )
>>> df.with_column("Total Nanoseconds", total_nanoseconds(df["duration"])).show()
╭──────────────┬───────────────────╮
│ duration ┆ Total Nanoseconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═══════════════════╡
│ 1s ┆ 1000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 1000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 1000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600000000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60000000000 │
╰──────────────┴───────────────────╯
<BLANKLINE>
(Showing first 6 of 6 rows)
"""
return Expression._call_builtin_scalar_fn("total_nanoseconds", expr)
|