Skip to content

Commit 0291021

Browse files
refactor(exprs): temporals (#4446)
## Changes Made Note: I did not move over the kernels because they are used for various partitioning functions throughout core and other crates. To move the kernels would be a bit bigger of a refactor that's out of scope for getting everything converted to the new `ScalarUDF` methods. ## Related Issues <!-- Link to related GitHub issues, e.g., "Closes #123" --> ## Checklist - [ ] Documented in API Docs (if applicable) - [ ] Documented in User Guide (if applicable) - [ ] If adding a new documentation page, doc is added to `docs/mkdocs.yml` navigation - [ ] Documentation builds and is formatted properly (tag @/ccmao1130 for docs review)
1 parent d66baf7 commit 0291021

File tree

25 files changed

+389
-808
lines changed

25 files changed

+389
-808
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ members = [
176176
"src/daft-functions-json",
177177
"src/daft-functions-list",
178178
"src/daft-functions-utf8",
179+
"src/daft-functions-temporal",
179180
"src/daft-hash",
180181
"src/daft-image",
181182
"src/daft-io",
@@ -199,8 +200,7 @@ members = [
199200
"src/hyperloglog",
200201
"src/parquet2",
201202
"src/generated/spark-connect",
202-
"src/daft-cli",
203-
"src/daft-functions-temporal"
203+
"src/daft-cli"
204204
]
205205

206206
[workspace.dependencies]
@@ -230,6 +230,7 @@ daft-functions = {path = "src/daft-functions"}
230230
daft-functions-binary = {path = "src/daft-functions-binary"}
231231
daft-functions-json = {path = "src/daft-functions-json"}
232232
daft-functions-list = {path = "src/daft-functions-list"}
233+
daft-functions-temporal = {path = "src/daft-functions-temporal"}
233234
daft-functions-utf8 = {path = "src/daft-functions-utf8"}
234235
daft-hash = {path = "src/daft-hash"}
235236
daft-local-execution = {path = "src/daft-local-execution"}

daft/daft/__init__.pyi

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,30 +1229,6 @@ class ConnectionHandle:
12291229
def shutdown(self) -> None: ...
12301230
def port(self) -> int: ...
12311231

1232-
# ---
1233-
# expr.dt namespace
1234-
# ---
1235-
def dt_date(expr: PyExpr) -> PyExpr: ...
1236-
def dt_day(expr: PyExpr) -> PyExpr: ...
1237-
def dt_hour(expr: PyExpr) -> PyExpr: ...
1238-
def dt_minute(expr: PyExpr) -> PyExpr: ...
1239-
def dt_second(expr: PyExpr) -> PyExpr: ...
1240-
def dt_millisecond(expr: PyExpr) -> PyExpr: ...
1241-
def dt_microsecond(expr: PyExpr) -> PyExpr: ...
1242-
def dt_nanosecond(expr: PyExpr) -> PyExpr: ...
1243-
def dt_unix_date(expr: PyExpr) -> PyExpr: ...
1244-
def dt_time(expr: PyExpr) -> PyExpr: ...
1245-
def dt_month(expr: PyExpr) -> PyExpr: ...
1246-
def dt_quarter(expr: PyExpr) -> PyExpr: ...
1247-
def dt_year(expr: PyExpr) -> PyExpr: ...
1248-
def dt_day_of_week(expr: PyExpr) -> PyExpr: ...
1249-
def dt_day_of_month(expr: PyExpr) -> PyExpr: ...
1250-
def dt_day_of_year(expr: PyExpr) -> PyExpr: ...
1251-
def dt_week_of_year(expr: PyExpr) -> PyExpr: ...
1252-
def dt_truncate(expr: PyExpr, interval: str, relative_to: PyExpr) -> PyExpr: ...
1253-
def dt_to_unix_epoch(expr: PyExpr, timeunit: PyTimeUnit) -> PyExpr: ...
1254-
def dt_strftime(expr: PyExpr, format: str | None = None) -> PyExpr: ...
1255-
12561232
# ---
12571233
# expr.list namespace
12581234
# ---
@@ -1339,26 +1315,6 @@ class PySeries:
13391315
def name(self) -> str: ...
13401316
def rename(self, name: str) -> PySeries: ...
13411317
def data_type(self) -> PyDataType: ...
1342-
def dt_date(self) -> PySeries: ...
1343-
def dt_day(self) -> PySeries: ...
1344-
def dt_hour(self) -> PySeries: ...
1345-
def dt_minute(self) -> PySeries: ...
1346-
def dt_second(self) -> PySeries: ...
1347-
def dt_millisecond(self) -> PySeries: ...
1348-
def dt_microsecond(self) -> PySeries: ...
1349-
def dt_nanosecond(self) -> PySeries: ...
1350-
def dt_unix_date(self) -> PySeries: ...
1351-
def dt_time(self) -> PySeries: ...
1352-
def dt_month(self) -> PySeries: ...
1353-
def dt_quarter(self) -> PySeries: ...
1354-
def dt_year(self) -> PySeries: ...
1355-
def dt_day_of_week(self) -> PySeries: ...
1356-
def dt_day_of_month(self) -> PySeries: ...
1357-
def dt_day_of_year(self) -> PySeries: ...
1358-
def dt_week_of_year(self) -> PySeries: ...
1359-
def dt_truncate(self, interval: str, relative_to: PySeries) -> PySeries: ...
1360-
def dt_strftime(self, format: str | None = None) -> PySeries: ...
1361-
def dt_to_unix_epoch(self, timeunit: PyTimeUnit) -> PySeries: ...
13621318
def partitioning_days(self) -> PySeries: ...
13631319
def partitioning_hours(self) -> PySeries: ...
13641320
def partitioning_months(self) -> PySeries: ...

daft/expressions/expressions.py

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ def date(self) -> Expression:
21682168
(Showing first 3 of 3 rows)
21692169
21702170
"""
2171-
return Expression._from_pyexpr(native.dt_date(self._expr))
2171+
return self._eval_expressions("date")
21722172

21732173
def day(self) -> Expression:
21742174
"""Retrieves the day for a datetime column.
@@ -2204,7 +2204,7 @@ def day(self) -> Expression:
22042204
(Showing first 3 of 3 rows)
22052205
22062206
"""
2207-
return Expression._from_pyexpr(native.dt_day(self._expr))
2207+
return self._eval_expressions("day")
22082208

22092209
def hour(self) -> Expression:
22102210
"""Retrieves the day for a datetime column.
@@ -2240,7 +2240,7 @@ def hour(self) -> Expression:
22402240
(Showing first 3 of 3 rows)
22412241
22422242
"""
2243-
return Expression._from_pyexpr(native.dt_hour(self._expr))
2243+
return self._eval_expressions("hour")
22442244

22452245
def minute(self) -> Expression:
22462246
"""Retrieves the minute for a datetime column.
@@ -2276,7 +2276,7 @@ def minute(self) -> Expression:
22762276
(Showing first 3 of 3 rows)
22772277
22782278
"""
2279-
return Expression._from_pyexpr(native.dt_minute(self._expr))
2279+
return self._eval_expressions("minute")
22802280

22812281
def second(self) -> Expression:
22822282
"""Retrieves the second for a datetime column.
@@ -2312,7 +2312,7 @@ def second(self) -> Expression:
23122312
(Showing first 3 of 3 rows)
23132313
23142314
"""
2315-
return Expression._from_pyexpr(native.dt_second(self._expr))
2315+
return self._eval_expressions("second")
23162316

23172317
def millisecond(self) -> Expression:
23182318
"""Retrieves the millisecond for a datetime column.
@@ -2345,7 +2345,7 @@ def millisecond(self) -> Expression:
23452345
<BLANKLINE>
23462346
(Showing first 3 of 3 rows)
23472347
"""
2348-
return Expression._from_pyexpr(native.dt_millisecond(self._expr))
2348+
return self._eval_expressions("millisecond")
23492349

23502350
def microsecond(self) -> Expression:
23512351
"""Retrieves the microsecond for a datetime column.
@@ -2378,7 +2378,7 @@ def microsecond(self) -> Expression:
23782378
(Showing first 3 of 3 rows)
23792379
23802380
"""
2381-
return Expression._from_pyexpr(native.dt_microsecond(self._expr))
2381+
return self._eval_expressions("microsecond")
23822382

23832383
def nanosecond(self) -> Expression:
23842384
"""Retrieves the nanosecond for a datetime column.
@@ -2412,7 +2412,7 @@ def nanosecond(self) -> Expression:
24122412
(Showing first 3 of 3 rows)
24132413
24142414
"""
2415-
return Expression._from_pyexpr(native.dt_nanosecond(self._expr))
2415+
return self._eval_expressions("nanosecond")
24162416

24172417
def unix_date(self) -> Expression:
24182418
"""Retrieves the number of days since 1970-01-01 00:00:00 UTC.
@@ -2449,7 +2449,7 @@ def unix_date(self) -> Expression:
24492449
(Showing first 3 of 3 rows)
24502450
24512451
"""
2452-
return Expression._from_pyexpr(native.dt_unix_date(self._expr))
2452+
return self._eval_expressions("unix_date")
24532453

24542454
def time(self) -> Expression:
24552455
"""Retrieves the time for a datetime column.
@@ -2485,7 +2485,7 @@ def time(self) -> Expression:
24852485
(Showing first 3 of 3 rows)
24862486
24872487
"""
2488-
return Expression._from_pyexpr(native.dt_time(self._expr))
2488+
return self._eval_expressions("time")
24892489

24902490
def month(self) -> Expression:
24912491
"""Retrieves the month for a datetime column.
@@ -2520,7 +2520,7 @@ def month(self) -> Expression:
25202520
(Showing first 3 of 3 rows)
25212521
25222522
"""
2523-
return Expression._from_pyexpr(native.dt_month(self._expr))
2523+
return self._eval_expressions("month")
25242524

25252525
def quarter(self) -> Expression:
25262526
"""Retrieves the quarter for a datetime column.
@@ -2555,7 +2555,7 @@ def quarter(self) -> Expression:
25552555
(Showing first 3 of 3 rows)
25562556
25572557
"""
2558-
return Expression._from_pyexpr(native.dt_quarter(self._expr))
2558+
return self._eval_expressions("quarter")
25592559

25602560
def year(self) -> Expression:
25612561
"""Retrieves the year for a datetime column.
@@ -2590,7 +2590,7 @@ def year(self) -> Expression:
25902590
(Showing first 3 of 3 rows)
25912591
25922592
"""
2593-
return Expression._from_pyexpr(native.dt_year(self._expr))
2593+
return self._eval_expressions("year")
25942594

25952595
def day_of_week(self) -> Expression:
25962596
"""Retrieves the day of the week for a datetime column, starting at 0 for Monday and ending at 6 for Sunday.
@@ -2625,7 +2625,7 @@ def day_of_week(self) -> Expression:
26252625
(Showing first 3 of 3 rows)
26262626
26272627
"""
2628-
return Expression._from_pyexpr(native.dt_day_of_week(self._expr))
2628+
return self._eval_expressions("day_of_week")
26292629

26302630
def day_of_month(self) -> Expression:
26312631
"""Retrieves the day of the month for a datetime column.
@@ -2663,7 +2663,7 @@ def day_of_month(self) -> Expression:
26632663
<BLANKLINE>
26642664
(Showing first 4 of 4 rows)
26652665
"""
2666-
return Expression._from_pyexpr(native.dt_day_of_month(self._expr))
2666+
return self._eval_expressions("day_of_month")
26672667

26682668
def day_of_year(self) -> Expression:
26692669
"""Retrieves the ordinal day for a datetime column. Starting at 1 for January 1st and ending at 365 or 366 for December 31st.
@@ -2701,7 +2701,7 @@ def day_of_year(self) -> Expression:
27012701
<BLANKLINE>
27022702
(Showing first 4 of 4 rows)
27032703
"""
2704-
return Expression._from_pyexpr(native.dt_day_of_year(self._expr))
2704+
return self._eval_expressions("day_of_year")
27052705

27062706
def week_of_year(self) -> Expression:
27072707
"""Retrieves the week of the year for a datetime column.
@@ -2739,7 +2739,7 @@ def week_of_year(self) -> Expression:
27392739
<BLANKLINE>
27402740
(Showing first 4 of 4 rows)
27412741
"""
2742-
return Expression._from_pyexpr(native.dt_week_of_year(self._expr))
2742+
return self._eval_expressions("week_of_year")
27432743

27442744
def truncate(self, interval: str, relative_to: Expression | None = None) -> Expression:
27452745
"""Truncates the datetime column to the specified interval.
@@ -2778,8 +2778,7 @@ def truncate(self, interval: str, relative_to: Expression | None = None) -> Expr
27782778
(Showing first 3 of 3 rows)
27792779
27802780
"""
2781-
relative_to = Expression._to_expression(relative_to)
2782-
return Expression._from_pyexpr(native.dt_truncate(self._expr, interval, relative_to._expr))
2781+
return self._eval_expressions("truncate", relative_to, interval=interval)
27832782

27842783
def to_unix_epoch(self, time_unit: str | TimeUnit | None = None) -> Expression:
27852784
"""Converts a datetime column to a Unix timestamp. with the specified time unit. (default: seconds).
@@ -2816,12 +2815,7 @@ def to_unix_epoch(self, time_unit: str | TimeUnit | None = None) -> Expression:
28162815
<BLANKLINE>
28172816
(Showing first 4 of 4 rows)
28182817
"""
2819-
if time_unit is None:
2820-
time_unit = TimeUnit.s()
2821-
if isinstance(time_unit, str):
2822-
time_unit = TimeUnit.from_str(time_unit)
2823-
2824-
return Expression._from_pyexpr(native.dt_to_unix_epoch(self._expr, time_unit._timeunit))
2818+
return self._eval_expressions("to_unix_epoch", time_unit=time_unit)
28252819

28262820
def strftime(self, format: str | None = None) -> Expression:
28272821
"""Converts a datetime/date column to a string column.
@@ -2869,7 +2863,7 @@ def strftime(self, format: str | None = None) -> Expression:
28692863
<BLANKLINE>
28702864
(Showing first 3 of 3 rows)
28712865
"""
2872-
return Expression._from_pyexpr(native.dt_strftime(self._expr, format))
2866+
return self._eval_expressions("strftime", format=format)
28732867

28742868
def total_seconds(self) -> Expression:
28752869
"""Calculates the total number of seconds for a duration column.
@@ -2913,8 +2907,7 @@ def total_seconds(self) -> Expression:
29132907
<BLANKLINE>
29142908
(Showing first 6 of 6 rows)
29152909
"""
2916-
f = native.get_function_from_registry("total_seconds")
2917-
return Expression._from_pyexpr(f(self._expr))
2910+
return self._eval_expressions("total_seconds")
29182911

29192912
def total_milliseconds(self) -> Expression:
29202913
"""Calculates the total number of milliseconds for a duration column.
@@ -2958,8 +2951,7 @@ def total_milliseconds(self) -> Expression:
29582951
<BLANKLINE>
29592952
(Showing first 6 of 6 rows)
29602953
"""
2961-
f = native.get_function_from_registry("total_milliseconds")
2962-
return Expression._from_pyexpr(f(self._expr))
2954+
return self._eval_expressions("total_milliseconds")
29632955

29642956
def total_microseconds(self) -> Expression:
29652957
"""Calculates the total number of microseconds for a duration column.
@@ -3003,8 +2995,7 @@ def total_microseconds(self) -> Expression:
30032995
<BLANKLINE>
30042996
(Showing first 6 of 6 rows)
30052997
"""
3006-
f = native.get_function_from_registry("total_microseconds")
3007-
return Expression._from_pyexpr(f(self._expr))
2998+
return self._eval_expressions("total_microseconds")
30082999

30093000
def total_nanoseconds(self) -> Expression:
30103001
"""Calculates the total number of nanoseconds for a duration column.
@@ -3048,8 +3039,7 @@ def total_nanoseconds(self) -> Expression:
30483039
<BLANKLINE>
30493040
(Showing first 6 of 6 rows)
30503041
"""
3051-
f = native.get_function_from_registry("total_nanoseconds")
3052-
return Expression._from_pyexpr(f(self._expr))
3042+
return self._eval_expressions("total_nanoseconds")
30533043

30543044
def total_minutes(self) -> Expression:
30553045
"""Calculates the total number of minutes for a duration column.
@@ -3093,8 +3083,7 @@ def total_minutes(self) -> Expression:
30933083
<BLANKLINE>
30943084
(Showing first 6 of 6 rows)
30953085
"""
3096-
f = native.get_function_from_registry("total_minutes")
3097-
return Expression._from_pyexpr(f(self._expr))
3086+
return self._eval_expressions("total_minutes")
30983087

30993088
def total_hours(self) -> Expression:
31003089
"""Calculates the total number of hours for a duration column.
@@ -3138,8 +3127,7 @@ def total_hours(self) -> Expression:
31383127
<BLANKLINE>
31393128
(Showing first 6 of 6 rows)
31403129
"""
3141-
f = native.get_function_from_registry("total_hours")
3142-
return Expression._from_pyexpr(f(self._expr))
3130+
return self._eval_expressions("total_hours")
31433131

31443132
def total_days(self) -> Expression:
31453133
"""Calculates the total number of days for a duration column.
@@ -3183,8 +3171,7 @@ def total_days(self) -> Expression:
31833171
<BLANKLINE>
31843172
(Showing first 6 of 6 rows)
31853173
"""
3186-
f = native.get_function_from_registry("total_days")
3187-
return Expression._from_pyexpr(f(self._expr))
3174+
return self._eval_expressions("total_days")
31883175

31893176

31903177
class ExpressionStringNamespace(ExpressionNamespace):

0 commit comments

Comments
 (0)