-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: remove ignores in refine_percentiles #42389
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
doesn't Sequence[float] cover the ndarray cases that we actually want? i.e. once it is supported, something like
np.ndarray[float, ndim=1] | None
would be what we really want?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 return type of refine_percentiles is a numpy array and we pass this onto the other functions, so we need to add np.ndarray to the acceptable types.
numpy/numpy#2776, issue has been opened a while, doesn't look like a fix in the pipeline
probably not
float
, sinceint
is also allowed. but if we narrow usingfloat
I've added the dtype bound to the return type of refine_percentiles since for return types we should be as precise as possible.
For the arguments of
describe
we want to be as permissible as possible, so maybe best not to narrow till the numpy inference works properly to avoid false positives for end users,describe
is public.'int' is duck type compatible with
float
, see https://mypy.readthedocs.io/en/stable/duck_type_compatibility.html#duck-type-compatibility, so havingSequence[float]
is equivalent toSequence[float | int]
on master
gives
but on master, users don't see false positives since the
percentiles
parameter ofDataFrame.describe
is not yet typedto type that, we need to pass the user passed argument onto the lower level functions, and these therefore need to be typed in a such a way to avoid false positives, so we can't wait for downstream fixes and imo best not to narrow types for numpy arrays till it's more mature.
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.
makes sense, thanks for walking me through that
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.
of course, passing integers
0
and1
is redundant anyway.and for the internal functions, using the type parameters for np.ndarray is probably also fine. it's only the public api where we may want to be more cautious.
to be clear, while the constructors don't specialize and the dtype type parameter of np.ndarray is
Any
, then they will be type compatible with any specializations we do add. If we get these wrong, then there could be a batch of errors that need to be resolved when we get a future numpy release.in numpy 1.21 (we use for type checking)...
so all arrays created with
np.array
will have an inferred typenumpy.ndarray[Any, Any]