Skip to content

daft.functions.total_nanoseconds#

total_nanoseconds #

total_nanoseconds(expr: Expression) -> Expression

Calculates the total number of nanoseconds for a duration column.

Returns:

Name Type Description
Expression Expression

a UInt64 expression with the total number of nanoseconds 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_nanoseconds
>>> 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 Nanoseconds", total_nanoseconds(df["duration"])).show()
╭──────────────┬───────────────────╮
│ duration     ┆ Total Nanoseconds │
│ ---          ┆ ---               │
│ Duration[us] ┆ Int64             │
╞══════════════╪═══════════════════╡
│ 1s           ┆ 1000000000        │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1000µs       ┆ 1000000           │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1µs          ┆ 1000              │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1d           ┆ 86400000000000    │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1h           ┆ 3600000000000     │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 1m           ┆ 60000000000       │
╰──────────────┴───────────────────╯
(Showing first 6 of 6 rows)
Source code in daft/functions/datetime.py
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
def total_nanoseconds(expr: Expression) -> Expression:
    """Calculates the total number of nanoseconds for a duration column.

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

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