Skip to content

daft.functions.time#

time #

time(expr: Expression) -> Expression

Retrieves the time for a datetime column.

Returns:

Name Type Description
Expression Expression

a Time expression

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
>>> import datetime
>>> import daft
>>> from daft.functions import time
>>> df = daft.from_pydict(
...     {
...         "x": [
...             datetime.datetime(2021, 1, 1, 0, 1, 1),
...             datetime.datetime(2021, 1, 1, 12, 1, 59),
...             datetime.datetime(2021, 1, 1, 23, 59, 59),
...         ],
...     }
... )
>>> df = df.with_column("time", time(df["x"]))
>>> df.show()
╭─────────────────────┬──────────╮
│ x                   ┆ time     │
│ ---                 ┆ ---      │
│ Timestamp[us]       ┆ Time[us] │
╞═════════════════════╪══════════╡
│ 2021-01-01 00:01:01 ┆ 00:01:01 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ 2021-01-01 12:01:59 ┆ 12:01:59 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
│ 2021-01-01 23:59:59 ┆ 23:59:59 │
╰─────────────────────┴──────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/datetime.py
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
def time(expr: Expression) -> Expression:
    """Retrieves the time for a datetime column.

    Returns:
        Expression: a Time expression

    Examples:
        >>> import datetime
        >>> import daft
        >>> from daft.functions import time
        >>> df = daft.from_pydict(
        ...     {
        ...         "x": [
        ...             datetime.datetime(2021, 1, 1, 0, 1, 1),
        ...             datetime.datetime(2021, 1, 1, 12, 1, 59),
        ...             datetime.datetime(2021, 1, 1, 23, 59, 59),
        ...         ],
        ...     }
        ... )
        >>> df = df.with_column("time", time(df["x"]))
        >>> df.show()
        ╭─────────────────────┬──────────╮
        │ x                   ┆ time     │
        │ ---                 ┆ ---      │
        │ Timestamp[us]       ┆ Time[us] │
        ╞═════════════════════╪══════════╡
        │ 2021-01-01 00:01:01 ┆ 00:01:01 │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
        │ 2021-01-01 12:01:59 ┆ 12:01:59 │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
        │ 2021-01-01 23:59:59 ┆ 23:59:59 │
        ╰─────────────────────┴──────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("time", expr)