Calculates the total number of seconds for a duration column.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt64 expression with the total number of seconds 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_seconds
>>> 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 Seconds", total_seconds(df["duration"])).show()
|
╭──────────────┬───────────────╮
│ duration ┆ Total Seconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═══════════════╡
│ 1s ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60 │
╰──────────────┴───────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780 | def total_seconds(expr: Expression) -> Expression:
"""Calculates the total number of seconds for a duration column.
Returns:
Expression: a UInt64 expression with the total number of seconds for a duration column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import total_seconds
>>> 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 Seconds", total_seconds(df["duration"])).show()
╭──────────────┬───────────────╮
│ duration ┆ Total Seconds │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═══════════════╡
│ 1s ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 86400 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 3600 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 60 │
╰──────────────┴───────────────╯
<BLANKLINE>
(Showing first 6 of 6 rows)
"""
return Expression._call_builtin_scalar_fn("total_seconds", expr)
|