-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
CLN: Fix typing in pandas\tests\arrays\test_datetimelike.py (#28926) #29014
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 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4046de
Merge pull request #1 from pandas-dev/master
jjlkant 871971b
Merge remote-tracking branch 'upstream/master'
jjlkant 89fdfb3
Merge remote-tracking branch 'upstream/master'
jjlkant 9953ad1
CLN: Fix typing in test_datetimelike.py (#28926)
jjlkant 136b9a8
CLN: Fix typing in test_datetimelike.py (#28926)
jjlkant 066da9d
Merge branch 'typing_test_datetimelike' of github.com:jjlkant/pandas …
jjlkant cc5614f
CLN: Sorted imports (GH28926)
jjlkant a4d0bc6
Merge remote-tracking branch 'upstream/master' into typing_test_datet…
jjlkant 5184b16
ENH: Added DatetimeLikeIndex alias (GH29014)
jjlkant 1e52b08
Revert to local Union defined type (GH29014)
jjlkant 9376f81
Merge remote-tracking branch 'upstream/master' into typing_test_datet…
jjlkant f94b7e4
Merge remote-tracking branch 'upstream/master' into typing_test_datet…
jjlkant 166fce9
Fixed merge conflict
jjlkant 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
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
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.
Can you put an alias for
DatetimeLikeIndex
in pandas._typing and use that here instead? I could see this being generally useful and we already have aDatetimeLikeScalar
defined there, so would be consistent@jbrockmendel in case he has other thoughts
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.
Very fair comment! Went ahead with an alias like:
Tried the route of using
TypeVar
as used forDatetimeLikeScalar
, but this sent me down a road with unbound type variables as a result ofindex_cls
being a class variable. In the case ofDatetimeLikeScalar
, the type hint was used on a@property
instead of a class variable, and without hinting inside of a comment. Do we want to go that way as well with this case?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.
Yea let's go with a
TypeVar
. Did that come when doingType[DatetimeLikeIndex]
? If so not sure off hand of solution so curious to see what you can find, but in any case the TypeVar is the right way to go hereThere 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.
Reading up on python/mypy#4590 as a result of looking into changing the class variables to
@property
, I think it is not possible to actually use aTypeVar
? The@property
looks as follows for example:I'm currently not seeing a route that will lead to the
TypeVar
behaving as expected. Will dive deeper into the current usage of otherTypeVar
entries in pandas._typing likeArrayLike
tomorrow, but any pointers are welcome in meantime!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.
What error would you get with
TypeVar
?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.
error: Incompatible return value type
for every entry that's not matching:With for example at L230-L238:
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.
Hmm OK I suppose these tests aren't fully generic so maybe the TypeVar doesn't work. I guess best to just revert to what you had, i.e. the Union def directly in the test module. Will leave the generic DatetimeLikeArray to a separate exercise as required
Sorry for back and forth but appreciate your thoroughness
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.
Yeah, if the regular
__init__(self)
would be available, the TypeVar was no issue at all, however pytest doesn't take classes that actually use an__init__(self)
. Rolled back to theUnion[]
version for now