-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix universal expressions on temporals (#895)
Expressions like (datecol + datecol) were not working, mostly because universal expressions for Python types were not allowed at the expressions level, so that has been fixed. Also: - Added names to series construction calls when available; without this, there were series name mismatch errors - py_binary_op didn't implement broadcast (and would silently produce undefined behaviour if the lengths mismatched); added broadcast to py_binary_op with a panic - Added simple tests for universal temporal ops --------- Co-authored-by: Xiayue Charles Lin <charles@eventualcomputing.com>
- Loading branch information
1 parent
547152b
commit 4ff216f
Showing
6 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime, timedelta, timezone | ||
|
||
import daft | ||
|
||
|
||
def test_temporal_arithmetic() -> None: | ||
now = datetime.now() | ||
now_tz = datetime.now(timezone.utc) | ||
df = daft.from_pydict( | ||
{ | ||
"dt_us": [datetime.min, now], | ||
"dt_us_tz": [datetime.min.replace(tzinfo=timezone.utc), now_tz], | ||
"duration": [timedelta(days=1), timedelta(microseconds=1)], | ||
} | ||
) | ||
|
||
df = df.select( | ||
(df["dt_us"] - df["dt_us"]).alias("zero1"), | ||
(df["dt_us_tz"] - df["dt_us_tz"]).alias("zero2"), | ||
(df["dt_us"] + (2 * df["duration"]) - df["duration"]).alias("addsub"), | ||
(df["dt_us_tz"] + (2 * df["duration"]) - df["duration"]).alias("addsub_tz"), | ||
(df["duration"] + df["duration"]).alias("add_dur"), | ||
) | ||
|
||
result = df.to_pydict() | ||
assert result["zero1"] == [timedelta(0), timedelta(0)] | ||
assert result["zero2"] == [timedelta(0), timedelta(0)] | ||
assert result["addsub"] == [datetime.min + timedelta(days=1), now + timedelta(microseconds=1)] | ||
assert result["addsub_tz"] == [ | ||
(datetime.min + timedelta(days=1)).replace(tzinfo=timezone.utc), | ||
now_tz + timedelta(microseconds=1), | ||
] | ||
assert result["add_dur"] == [timedelta(days=2), timedelta(microseconds=2)] |