Deprecate Expr temporal part arguments in date extraction and truncation functions#1587
Open
kosiew wants to merge 3 commits into
Open
Deprecate Expr temporal part arguments in date extraction and truncation functions#1587kosiew wants to merge 3 commits into
Expr temporal part arguments in date extraction and truncation functions#1587kosiew wants to merge 3 commits into
Conversation
- Added a deprecation warning helper in `functions.py` to warn users when an `Expr` is passed to: - `date_part` - `datepart` - `extract` - `date_trunc` - `datetrunc` - Kept plain string paths unchanged. test: enhance tests for deprecation warnings - Added tests in `test_functions.py` to check for deprecation warnings. - Implemented no-warning checks for native strings. - Updated an existing temporal test to use strings to reduce warning noise.
…g in data fusion functions
- Changed f.date_part(literal("month"), ...) to f.date_part("month", ...)
- Changed f.extract(literal("day"), ...) to f.extract("day", ...)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Rationale for this change
Temporal functions such as
date_part,date_trunc, and their aliases conceptually expect a literal date/time part (for example,"year"or"month"). While the current API also accepts anExpr, that usage is confusing because it suggests arbitrary expressions are intended inputs.This change begins the deprecation process by warning when an
Expris passed for thepartargument while preserving existing runtime behavior.What changes are included in this PR?
Added a shared helper to emit a
DeprecationWarningwhen anExpris passed to a literal control argument.Updated the implementations of:
date_partdatepartextractdate_truncdatetruncto warn when
partis provided as anExpr.Refactored alias functions (
datepart,extract, anddatetrunc) to delegate through internal helper functions so warnings reference the user-facing function name correctly and avoid duplicate warning behavior.Updated existing temporal function tests to use the preferred string-literal form for
part.Added targeted tests verifying:
Exprinputs emitDeprecationWarningfordate_part,datepart, andextract.Exprinputs emitDeprecationWarningfordate_truncanddatetrunc.Are these changes tested?
Yes.
The PR updates existing temporal function tests and adds the following deprecation-focused test coverage:
test_date_part_expr_part_warns_deprecatedtest_date_trunc_expr_part_warns_deprecatedIt also verifies that preferred string-literal usage does not emit
DeprecationWarningby running:test_date_part_native_strtest_date_trunc_native_strwith deprecation warnings treated as errors.
Are there any user-facing changes?
Yes.
Passing an
Expr(for example,literal("year")) as thepartargument to temporal extraction and truncation functions now emits aDeprecationWarningadvising users to pass a Python literal string instead.Runtime behavior and query results remain unchanged in this release.
LLM-generated code disclosure
This PR includes code, comments generated with assistance from LLM. All LLM-generated content has been manually reviewed and tested.