-
Notifications
You must be signed in to change notification settings - Fork 67
feat: (Preview) Support arithmetics between dates and timedeltas #1413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6261df8
[WIP] Implement date_diff, date_add, and date_sub. Some tests are bro…
sycai dcb432e
Merge branch 'main' into sycai_date_arithmetics
sycai b50e998
fix format
sycai 2c6c5e2
change implementation to emulate PyArrow
sycai 34f344b
fix mypy
sycai 72fa2e8
fix format
sycai 59cb5ec
fix tests
sycai dc21607
Merge branch 'main' into sycai_date_arithmetics
sycai 558b7dd
fix more tests
sycai 7c49b18
Merge branch 'main' into sycai_date_arithmetics
sycai 0113cd1
bump pyarrow dependency to 15.0.2
sycai 6bce096
raise pandas version in system-3.12 tests
sycai 281f463
fix format
sycai 45a4706
restore constraints-3.12
sycai 3868eb7
raise pandas version to 2.2.0 in 3.12 testing env
sycai 3667746
Merge branch 'main' into sycai_date_arithmetics
sycai dc1e948
Merge branch 'main' into sycai_date_arithmetics
sycai 90c7d92
remove pandas constraints for 3.12
sycai d83a572
Merge branch 'main' into sycai_date_arithmetics
sycai d7f2dbd
fix merge error
sycai f86b5f2
cast factor to int instead of calling floor()
sycai d977517
Merge branch 'main' into sycai_date_arithmetics
sycai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -740,6 +740,21 @@ def timestamp_sub_op_impl(x: ibis_types.TimestampValue, y: ibis_types.IntegerVal | |
| return x - y.to_interval("us") | ||
|
|
||
|
|
||
| @scalar_op_compiler.register_binary_op(ops.date_diff_op) | ||
| def date_diff_op_impl(x: ibis_types.DateValue, y: ibis_types.DateValue): | ||
| return x.delta(y, "day") * int(UNIT_TO_US_CONVERSION_FACTORS["d"]) # type: ignore | ||
|
|
||
|
|
||
| @scalar_op_compiler.register_binary_op(ops.date_add_op) | ||
| def date_add_op_impl(x: ibis_types.DateValue, y: ibis_types.IntegerValue): | ||
| return x.cast("timestamp") + y.to_interval("us") # type: ignore | ||
|
|
||
|
|
||
| @scalar_op_compiler.register_binary_op(ops.date_sub_op) | ||
| def date_sub_op_impl(x: ibis_types.DateValue, y: ibis_types.IntegerValue): | ||
| return x.cast("timestamp") - y.to_interval("us") # type: ignore | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, would rather avoid casting to interval type
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as above. |
||
|
|
||
|
|
||
| @scalar_op_compiler.register_unary_op(ops.FloorDtOp, pass_op=True) | ||
| def floor_dt_op_impl(x: ibis_types.Value, op: ops.FloorDtOp): | ||
| supported_freqs = ["Y", "Q", "M", "W", "D", "h", "min", "s", "ms", "us", "ns"] | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we convert to interval datatype? I would rather just use https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_add with an integer.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the interval conversion because this is how Ibis generates
date_addexpressions. In other words, Ibis only recognizesDateValue + IntervalValueto getDATE_ADD(Date, Interval ...)