Calculates the total number of hours for a duration column.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt64 expression with the total number of hours 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_hours
>>> 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 Hours", total_hours(df["duration"])).show()
|
╭──────────────┬─────────────╮
│ duration ┆ Total Hours │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═════════════╡
│ 1s ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 24 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 0 │
╰──────────────┴─────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990 | def total_hours(expr: Expression) -> Expression:
"""Calculates the total number of hours for a duration column.
Returns:
Expression: a UInt64 expression with the total number of hours for a duration column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import total_hours
>>> 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 Hours", total_hours(df["duration"])).show()
╭──────────────┬─────────────╮
│ duration ┆ Total Hours │
│ --- ┆ --- │
│ Duration[us] ┆ Int64 │
╞══════════════╪═════════════╡
│ 1s ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs ┆ 0 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d ┆ 24 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m ┆ 0 │
╰──────────────┴─────────────╯
<BLANKLINE>
(Showing first 6 of 6 rows)
"""
return Expression._call_builtin_scalar_fn("total_hours", expr)
|