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.
TYP: Add cast to ABC classes. #37902
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
TYP: Add cast to ABC classes. #37902
Changes from 2 commits
8a466ac
99c9e6b
f8a76bc
c9a31a4
1ac7c9e
2ba5fbe
bcd0257
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
the problem here is that AnyArrayLike is a typevar and also the type of
obj
is wrong anyway and should beobject
I think could also changeobj
to object/Any for now until we overload and keep the implementation unchanged.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 revert the changes to the implementation.
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.
Yes, but would require adding
obj = obj.array # type: ignore[assignment]
or possibly changing typing on arguments (not return type)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.
IIUC this is a similar issue to #37902 (comment) where we changed FrameOrSeries to FrameOrSeriesUnion.
We don't yet have an AnyArrayLikeUnion to do the same here.
because AnyArrayLike is a typevar, the type annotations imply that the type doesn't change.
This is not true. Only for np.ndarray and ExtensionArray if extract_array=False.
so maybe the signature should be
but we also need to overload (to account for Series and Index array extraction) but while numpy types resolve to
Any
we get mypy errors about overlapping overloads.so for now, i think ok to do...
It's the use of the typevar that causes the issue, so I'm not too concerned what type annotations are chosen at this stage, so long as we are not changing the implementation because we are using a TypeVar incorrectly.
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.
Thanks for the explanation! Changes made.
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.
the changes in this module are not required. The mypy issue is trying to assign the result of data._to_frame back to data which is FrameOrSeries, a typevar.
just need to change FrameOrSeries to FrameOrSeriesUnion in the function signature.
I think the defaults in pandas._typing should be changed to Unions. see also #36092 (comment) about ArrayLike and AnyArrayLike