Calculates the total number of microseconds for a duration column.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt64 expression with the total number of microseconds 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_microseconds
>>> 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 Microseconds", total_microseconds(df["duration"])).show()
|
╭──────────────┬────────────────────╮
│ duration ┆ Total Microseconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪════════════════════╡
│ 1s ┆ 1000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 1000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60000000 │
╰──────────────┴────────────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 | def total_microseconds(expr: Expression) -> Expression:
"""Calculates the total number of microseconds for a duration column.
Returns:
Expression: a UInt64 expression with the total number of microseconds for a duration column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import total_microseconds
>>> 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 Microseconds", total_microseconds(df["duration"])).show()
╭──────────────┬────────────────────╮
│ duration ┆ Total Microseconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪════════════════════╡
│ 1s ┆ 1000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 1000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600000000 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60000000 │
╰──────────────┴────────────────────╯
<BLANKLINE>
(Showing first 6 of 6 rows)
"""
return Expression._call_builtin_scalar_fn("total_microseconds", expr)
|