-
-
Notifications
You must be signed in to change notification settings - Fork 141
GH984 Add overload for DataFrame.clip and update those for Series.clip #1206
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
base: main
Are you sure you want to change the base?
Conversation
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 tests where either lower
or upper
is not specified?
I think that might lead to some changes in how you wrote the overloads.
Turns out no changes were needed but agreed that this time we check all the cases. |
I'm a little confused here, as you closed the PR and then reopened it. Should I review? |
Yes it is open for review, I have accidentally pressed the close button, my
mistake.
…On Wed, Apr 30, 2025 at 9:46 AM Irv Lustig ***@***.***> wrote:
*Dr-Irv* left a comment (pandas-dev/pandas-stubs#1206)
<#1206 (comment)>
I'm a little confused here, as you closed the PR and then reopened it.
Should I review?
—
Reply to this email directly, view it on GitHub
<#1206 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMQNSQBKOZWMMGWLDPGFMV324DH4LAVCNFSM6AAAAAB4BXDTWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQNBSGA2DOOJRHA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
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 you may also need similar overloads for clip
in series.pyi
and then similar tests that omit the lower
or upper
arguments.
tests/test_frame.py
Outdated
check(assert_type(df.clip(upper=None, axis="index"), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.clip(upper=15, axis="index"), pd.DataFrame), pd.DataFrame) | ||
check(assert_type(df.clip(upper=None, axis="index"), pd.DataFrame), pd.DataFrame) |
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.
lines 808 and 810 are the same
tests/test_frame.py
Outdated
assert_type(df.clip(lower=None, axis="index"), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=5, axis="index"), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=None, axis="index"), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=pd.Series([1, 2]), axis="index"), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=None, axis="index"), pd.DataFrame), | ||
pd.DataFrame, | ||
) |
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.
lines 863 and 871 and 879 are the same test
tests/test_frame.py
Outdated
assert_type(df.clip(lower=None, axis="index", inplace=True), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=5, axis="index", inplace=True), None), | ||
type(None), | ||
) | ||
check( | ||
assert_type(df.clip(lower=pd.Series([1, 2]), axis="index", inplace=True), None), | ||
type(None), | ||
) | ||
check( | ||
assert_type(df.clip(lower=None, axis="index", inplace=True), pd.DataFrame), |
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.
lines 847 and 859 are the same test
tests/test_frame.py
Outdated
assert_type(df.clip(lower=None, axis=0, inplace=True), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check(assert_type(df.clip(lower=5, axis=0, inplace=True), None), type(None)) | ||
check( | ||
assert_type(df.clip(lower=None, axis=0, inplace=True), pd.DataFrame), |
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.
lines 883 and 888 are the same test
assert_type(df.clip(lower=None, axis=None, inplace=True), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
check( | ||
assert_type(df.clip(lower=5, axis=None, inplace=True), None), | ||
type(None), | ||
) | ||
check( | ||
assert_type(df.clip(lower=None, axis=None, inplace=True), pd.DataFrame), | ||
pd.DataFrame, |
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.
lines 828 and 836 are the same test
Since clip for series does not use the axis when passing a list like
argument to lower or upper the overloads are already there. Let me clean up
the tests and add for those without upper or lower passed and we should be
in a good place, the big work was on the data frame side.
…On Wed, Apr 30, 2025 at 11:50 AM Irv Lustig ***@***.***> wrote:
***@***.**** requested changes on this pull request.
I think you may also need similar overloads for clip in series.pyi and
then similar tests that omit the lower or upper arguments.
------------------------------
In tests/test_frame.py
<#1206 (comment)>
:
> + check(assert_type(df.clip(upper=None, axis="index"), pd.DataFrame), pd.DataFrame)
+ check(assert_type(df.clip(upper=15, axis="index"), pd.DataFrame), pd.DataFrame)
+ check(assert_type(df.clip(upper=None, axis="index"), pd.DataFrame), pd.DataFrame)
lines 808 and 810 are the same
------------------------------
In tests/test_frame.py
<#1206 (comment)>
:
> + assert_type(df.clip(lower=None, axis="index"), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=5, axis="index"), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=None, axis="index"), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=pd.Series([1, 2]), axis="index"), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=None, axis="index"), pd.DataFrame),
+ pd.DataFrame,
+ )
lines 863 and 871 and 879 are the same test
------------------------------
In tests/test_frame.py
<#1206 (comment)>
:
> + assert_type(df.clip(lower=None, axis="index", inplace=True), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=5, axis="index", inplace=True), None),
+ type(None),
+ )
+ check(
+ assert_type(df.clip(lower=pd.Series([1, 2]), axis="index", inplace=True), None),
+ type(None),
+ )
+ check(
+ assert_type(df.clip(lower=None, axis="index", inplace=True), pd.DataFrame),
lines 847 and 859 are the same test
------------------------------
In tests/test_frame.py
<#1206 (comment)>
:
> + assert_type(df.clip(lower=None, axis=0, inplace=True), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(assert_type(df.clip(lower=5, axis=0, inplace=True), None), type(None))
+ check(
+ assert_type(df.clip(lower=None, axis=0, inplace=True), pd.DataFrame),
lines 883 and 888 are the same test
------------------------------
In tests/test_frame.py
<#1206 (comment)>
:
> + assert_type(df.clip(lower=None, axis=None, inplace=True), pd.DataFrame),
+ pd.DataFrame,
+ )
+ check(
+ assert_type(df.clip(lower=5, axis=None, inplace=True), None),
+ type(None),
+ )
+ check(
+ assert_type(df.clip(lower=None, axis=None, inplace=True), pd.DataFrame),
+ pd.DataFrame,
lines 828 and 836 are the same test
—
Reply to this email directly, view it on GitHub
<#1206 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMQNSQB5TEGEXPERXRNI5T324DWOBAVCNFSM6AAAAAB4BXDTWOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDQMBXGUYTGNBUGM>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Turns out the axis parameter does not need anything specific (to split the overloads) since it is not used (unless you pass something not allowed). |
DataFrame.clip()
#984assert_type()
to assert the type of any return valueTurns out there is a nasty edge case when you pass everything as None for upper and lower and ask for
inplace=True
, it will returnSelf
and notNone
.