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.
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: core/dtypes/cast.py #37024
TYP: core/dtypes/cast.py #37024
Changes from all commits
b4e582f
2cc7e97
8da843d
fc757c0
8999b35
d054868
92d94b0
a5e9800
afd887b
7f4e93e
3be4aba
25ce7ed
3aa7e4d
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.
ArrayLike
is a TypeVar. so the return type is typed to be the same as obj.I think mypy is accepting this since np.ndarray resolves to
Any
We probably need an ArrayLikeUnion, but this is perhaps out of scope here as the discussion has been started elsewhere. xref #36100
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.
Shall I remove the annotation and add a TODO?
As an aside FWIW I like the
ArrayLike
/ArrayLikeT
idea in https://github.com/pandas-dev/pandas/pull/36100/files#r483753222There 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.
you can leave as is for now. we have #36092 to track the issues once np.ndarray no longer resolves to Any.
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 was this added? mypy is not reporting any errors for me with this removed.
generally, try to avoid adding variable type annotations. should be inferred from expression.
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.
mistake, will revert
I had tried typing
index
andcodes
but there were a lot of errors - this was part of an attempted fix.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 update the docstring to match?
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.
Done
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 never get EAs here?
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.
Atm the only use case is here:
pandas/pandas/core/construction.py
Lines 538 to 557 in 126f3cc
which according to docstring excludes
ExtensionArray
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 add an assert in the body itself to lock this down. (whether we want it or not is different, but guarantee is good for now)
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.
Added
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 just pass shape onto np.empty, https://numpy.org/doc/1.19/reference/generated/numpy.empty.html
so could be int or tuple of int
I recall a discussion about adding an alias to pandas._typing or
and the docstring would need to be updated too.
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.
Pushed the suggestion.
Adding an alias to _typing sounds like a good idea. Do we already have a PR on that or shall I submit one?
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.
I don't think so, go ahead.