Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

loicdiridollou
Copy link
Member

@loicdiridollou loicdiridollou commented Apr 29, 2025

Turns out there is a nasty edge case when you pass everything as None for upper and lower and ask for inplace=True, it will return Self and not None.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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.

@loicdiridollou
Copy link
Member Author

Turns out no changes were needed but agreed that this time we check all the cases.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 30, 2025

I'm a little confused here, as you closed the PR and then reopened it. Should I review?

@loicdiridollou
Copy link
Member Author

loicdiridollou commented Apr 30, 2025 via email

Copy link
Collaborator

@Dr-Irv Dr-Irv left a 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.

Comment on lines 808 to 810
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)
Copy link
Collaborator

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

Comment on lines 863 to 881
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,
)
Copy link
Collaborator

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

Comment on lines 847 to 859
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),
Copy link
Collaborator

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

Comment on lines 883 to 888
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),
Copy link
Collaborator

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

Comment on lines +828 to +837
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,
Copy link
Collaborator

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

@loicdiridollou
Copy link
Member Author

loicdiridollou commented Apr 30, 2025 via email

@loicdiridollou
Copy link
Member Author

loicdiridollou commented May 1, 2025

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).
So the overload did not need anything additional yet I have added more tests to lock in the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create overloads for DataFrame.clip()
2 participants