Skip to content

daft.functions.total_minutes#

total_minutes #

total_minutes(expr: Expression) -> Expression

Calculates the total number of minutes for a duration column.

Returns:

Name Type Description
Expression Expression

a UInt64 expression with the total number of minutes 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_minutes
>>> 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 Minutes", total_minutes(df["duration"])).show()
╭──────────────┬───────────────╮
│ duration     ┆ Total Minutes │
│ ---          ┆ ---           │
│ Duration[us] ┆ Int64         │
╞══════════════╪═══════════════╡
│ 1s           ┆ 0             │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs       ┆ 0             │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs          ┆ 0             │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d           ┆ 1440          │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h           ┆ 60            │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m           ┆ 1             │
╰──────────────┴───────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
def total_minutes(expr: Expression) -> Expression:
    """Calculates the total number of minutes for a duration column.

    Returns:
        Expression: a UInt64 expression with the total number of minutes for a duration column

    Examples:
        >>> import datetime
        >>> import daft
        >>> from daft.functions import total_minutes
        >>> 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 Minutes", total_minutes(df["duration"])).show()
        ╭──────────────┬───────────────╮
        │ duration     ┆ Total Minutes │
        │ ---          ┆ ---           │
        │ Duration[us] ┆ Int64         │
        ╞══════════════╪═══════════════╡
        │ 1s           ┆ 0             │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1000µs       ┆ 0             │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1µs          ┆ 0             │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1d           ┆ 1440          │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1h           ┆ 60            │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 1m           ┆ 1             │
        ╰──────────────┴───────────────╯
        <BLANKLINE>
        (Showing first 6 of 6 rows)
    """
    return Expression._call_builtin_scalar_fn("total_minutes", expr)