Skip to content
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

lower and upper from DataFrame.clip don't accept array-like #980

Closed
ldouteau opened this issue Aug 20, 2024 · 1 comment · Fixed by #982
Closed

lower and upper from DataFrame.clip don't accept array-like #980

ldouteau opened this issue Aug 20, 2024 · 1 comment · Fixed by #982

Comments

@ldouteau
Copy link
Contributor

Describe the bug
Hi,

There is an inconsistency with Pandas's doc regarding clip. This was already fixed for Series in #443, but not for DataFrame

def clip(
self,
lower: float | None = ...,
upper: float | None = ...,
*,
axis: Axis | None = ...,
inplace: _bool = ...,
**kwargs,
) -> DataFrame: ...

To Reproduce

  1. From https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.clip.html
import pandas as pd

data = {"col_0": [9, -3, 0, -1, 5], "col_1": [-2, -7, 6, 8, -5]}
df = pd.DataFrame(data)
t = pd.Series([2, -4, -1, 6, 3])
df.clip(t, t + 4, axis=0)
  1. Pyright 1.1.373
Argument of type "Series[int]" cannot be assigned to parameter "upper" of type "float | None" in function "clip"
  Type "Series[int]" is incompatible with type "float | None"
    "Series[int]" is incompatible with "float"
    "Series[int]" is incompatible with "None"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)

Please complete the following information:

  • OS: Windows 11
  • OS Version 23H2
  • python version 3.12.2
  • version of type checker: Pyright 1.1.373
  • version of installed pandas-stubs: 2.2.2.240807
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Aug 20, 2024

Thanks for the report. PR with tests welcome.

ldouteau added a commit to ldouteau/pandas-stubs that referenced this issue Aug 21, 2024
ldouteau added a commit to ldouteau/pandas-stubs that referenced this issue Aug 21, 2024
Dr-Irv pushed a commit that referenced this issue Aug 21, 2024
#982)

* Supports arrays in DataFrame.clip (#980)

* add missing assert_type (#980)

* check the content of asserted type
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 a pull request may close this issue.

2 participants