Retrieves the second for a datetime column.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt32 expression with just the second 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 second
>>> df = daft.from_pydict(
... {
... "x": [
... datetime.datetime(2021, 1, 1, 0, 1, 1),
... datetime.datetime(2021, 1, 1, 0, 1, 59),
... datetime.datetime(2021, 1, 1, 0, 2, 0),
... ],
... }
... )
>>> df = df.with_column("second", second(df["x"]))
>>> df.show()
|
╭─────────────────────┬────────╮
│ x ┆ second │
│ --- ┆ --- │
│ Timestamp[us] ┆ UInt32 │
╞═════════════════════╪════════╡
│ 2021-01-01 00:01:01 ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:01:59 ┆ 59 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:02:00 ┆ 0 │
╰─────────────────────┴────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/datetime.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 | def second(expr: Expression) -> Expression:
"""Retrieves the second for a datetime column.
Returns:
Expression: a UInt32 expression with just the second extracted from a datetime column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import second
>>> df = daft.from_pydict(
... {
... "x": [
... datetime.datetime(2021, 1, 1, 0, 1, 1),
... datetime.datetime(2021, 1, 1, 0, 1, 59),
... datetime.datetime(2021, 1, 1, 0, 2, 0),
... ],
... }
... )
>>> df = df.with_column("second", second(df["x"]))
>>> df.show()
╭─────────────────────┬────────╮
│ x ┆ second │
│ --- ┆ --- │
│ Timestamp[us] ┆ UInt32 │
╞═════════════════════╪════════╡
│ 2021-01-01 00:01:01 ┆ 1 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:01:59 ┆ 59 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:02:00 ┆ 0 │
╰─────────────────────┴────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("second", expr)
|