-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Add support for arrays in lower
and upper
args of DataFrame.clip
#982
Merged
Merged
Changes from 2 commits
Commits
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 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 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.
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.
It's possible (but not required) that you could also handle this via typing checks by creating overloads that are the acceptable combinations of the arguments
lower
,upper
andaxis
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'm OK to approve this as is, but let me know if you want to try to make these changes I suggested as part of this PR.
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'm not sure how to type the fact that "either one of
lower
orupper
is ArrayLike". If you have any suggestion to propose, i can add overloadsRegarding the test i think it should stay as-is, as it tests the pandas version of the function
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.
Just thinking of this implementation. One question though: the case where
upper
andlower
are both arrays is covered by both overloads. Is that an issue ? I'm not that familiar with overloads in generalThere 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 that is required.
df.clip()
works fine, as doesdf.clip(3, 4)
. So maybe your test isn't right?If you can get the overloads to work, then you'd add tests using
TYPE_CHECKING_INVALID_USAGE
to make sure the type checkers caught the invalid usage. But I'm now not sure the overloads are needed.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.
Well the test is not exhaustive:
df.clip([1, 2])
will pass butdf.clip(pd.Series([1, 2]))
will fail with a value error.What's your opinion on this ? Getting dedicated overloads using pd.Series ?
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 think the solution here is to disallow
None
as follows:Testing this means you have to move away from using
pytest.mark.parameterize
, and explicitly test each possible condition. This is preferred anyway from how we want to test the types.You can use
assert_never()
to test the cases where it should fail.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 think this is pretty complicated, because you need to have overloads for each combination where
axis=None
and usingAnyArrayLike
corresponds toNever
, but usingAnyArrayLike
requiresaxis
to be specified and not beNone
.I'm going to approve this PR as is - it's an improvement, and if you want to experiment with the overloads, that could be a separate PR. Created #984 to track that.