Skip to content

daft.functions.total_milliseconds#

total_milliseconds #

total_milliseconds(expr: Expression) -> Expression

Calculates the total number of milliseconds for a duration column.

Returns:

Name Type Description
Expression Expression

a UInt64 expression with the total number of milliseconds 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_milliseconds
>>> 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 Milliseconds", total_milliseconds(df["duration"])).show()
╭──────────────┬────────────────────╮
│ duration     ┆ Total Milliseconds │
│ ---          ┆ ---                │
│ Duration[us] ┆ Int64              │
╞══════════════╪════════════════════╡
│ 1s           ┆ 1000               │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs       ┆ 1                  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs          ┆ 0                  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d           ┆ 86400000           │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h           ┆ 3600000            │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m           ┆ 60000              │
╰──────────────┴────────────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
def total_milliseconds(expr: Expression) -> Expression:
    """Calculates the total number of milliseconds for a duration column.

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

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