-
Notifications
You must be signed in to change notification settings - Fork 176
refactor: Simplify calculate_timestamp_datetime and calculate_timestamp_date
#2838
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
FBruzzesi
merged 4 commits into
main
from
refactor/simplify-calculate_timestamp_datetime
Jul 17, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e6def9
refactor: Simplify calculate_timestamp_datetime and calculate_timestaβ¦
FBruzzesi bdb46aa
fix(typing): Remove `NativeSeriesT` from alias def
dangotbanned eb8ec7f
Merge remote-tracking branch 'upstream/main' into refactor/simplify-cβ¦
dangotbanned 86efcc7
Merge branch 'main' into refactor/simplify-calculate_timestamp_datetime
dangotbanned 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
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.
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.
#2838 (comment)
I think the issue is that
BinOpBroadcastis generic, but using aTypeVarwith a default.So you don't get a warning when using
BinOpBroadcastwithout specialising - but it causes an issue later when the default conflicts with the constraints of the function signature.Hopefully this works, I'm replying from my phone π
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.
narwhals/narwhals/_pandas_like/typing.py
Lines 25 to 31 in bb03703
NativeSeriesTmeans exactly one ofpd.Series[Any],_CuDFSeries,_ModinSeries, but default topd.Series[Any]when not provided.So the conflict is that
NativeSeriesTis still used for the function parameter and return type_TIMESTAMP_DATETIME_OP_FACTORis currently saying it only acceptspd.Series[Any]narwhals/narwhals/_pandas_like/utils.py
Lines 576 to 578 in 0e6def9
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.
Hey @dangotbanned thanks for investigating this.
Why would that be the case? The definition is:
BinOpBroadcast: TypeAlias = Callable[[NativeSeriesT, int], NativeSeriesT]Regarding #2838 (comment),
BinOpBroadcastis not a generic, and it would result in:π§
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.
BinOpBroadcastis a genericTypeAliasbecause it uses aTypeVar(NativeSeriesT) in it's definition.If we compare that to when you hover over the current use, it uses the default type - because it wasn't subscribed
Ahh, so that message it about scoping - not that the
TypeVarcan't be used at allSo this is because
_TIMESTAMP_DATETIME_OP_FACTORis in a global scope, but we're trying to solve theTypeVarin a function scopeThere 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.
I've just used
Anyinstead in (bdb46aa)The main reason I had that typing in
_arrowwas because the stubs caused too many false positives when I used the functions directly.Here, we're just using
operatorfunctions, which are mostly typed withAnyanyway πhttps://github.com/python/typeshed/blob/8e25bda401332ac56d4750cffda2127a4302cd2f/stdlib/_operator.pyi#L42-L71
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 still have
NativeSeriesTpreserved on the outside, so this is simpler than refactoring everything to provide a scope for theTypeVarπ