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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852 | 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)
|