Skip to content

daft.functions.day#

day #

day(expr: Expression) -> Expression

Retrieves the day for a datetime column.

Returns:

Name Type Description
Expression Expression

a UInt32 expression with just the day extracted from a datetime column

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
>>> import datetime
>>> import daft
>>> from daft.functions import day
>>> df = daft.from_pydict(
...     {
...         "x": [
...             datetime.datetime(2021, 1, 1, 5, 1, 1),
...             datetime.datetime(2021, 1, 2, 6, 1, 59),
...             datetime.datetime(2021, 1, 3, 7, 2, 0),
...         ],
...     }
... )
>>> df = df.with_column("day", day(df["x"]))
>>> df.show()
╭─────────────────────┬────────╮
│ x                   ┆ day    │
│ ---                 ┆ ---    │
│ Timestamp[us]       ┆ UInt32 │
╞═════════════════════╪════════╡
│ 2021-01-01 05:01:01 ┆ 1      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-02 06:01:59 ┆ 2      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-03 07:02:00 ┆ 3      │
╰─────────────────────┴────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/datetime.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def day(expr: Expression) -> Expression:
    """Retrieves the day for a datetime column.

    Returns:
        Expression: a UInt32 expression with just the day extracted from a datetime column

    Examples:
        >>> import datetime
        >>> import daft
        >>> from daft.functions import day
        >>> df = daft.from_pydict(
        ...     {
        ...         "x": [
        ...             datetime.datetime(2021, 1, 1, 5, 1, 1),
        ...             datetime.datetime(2021, 1, 2, 6, 1, 59),
        ...             datetime.datetime(2021, 1, 3, 7, 2, 0),
        ...         ],
        ...     }
        ... )
        >>> df = df.with_column("day", day(df["x"]))
        >>> df.show()
        ╭─────────────────────┬────────╮
        │ x                   ┆ day    │
        │ ---                 ┆ ---    │
        │ Timestamp[us]       ┆ UInt32 │
        ╞═════════════════════╪════════╡
        │ 2021-01-01 05:01:01 ┆ 1      │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
        │ 2021-01-02 06:01:59 ┆ 2      │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
        │ 2021-01-03 07:02:00 ┆ 3      │
        ╰─────────────────────┴────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

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