Skip to content

TYP return type of DataFrame.clip not correct #40829

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

Closed
MarcoGorelli opened this issue Apr 7, 2021 · 7 comments · Fixed by #40860
Closed

TYP return type of DataFrame.clip not correct #40829

MarcoGorelli opened this issue Apr 7, 2021 · 7 comments · Fixed by #40860
Assignees
Labels
good first issue Typing type annotations, mypy/pyright type checking

Comments

@MarcoGorelli
Copy link
Member

pandas/pandas/core/generic.py

Lines 7449 to 7458 in 094f630

@final
def clip(
self: FrameOrSeries,
lower=None,
upper=None,
axis=None,
inplace: bool_t = False,
*args,
**kwargs,
) -> FrameOrSeries:

Return type should be Optional[FrameOrSeriesUnion]

It could also do with being overloaded according to the value of inplace - see set_axis and DataFrame.reset_index for examples

@MarcoGorelli MarcoGorelli added good first issue Typing type annotations, mypy/pyright type checking labels Apr 7, 2021
@DriesSchaumont
Copy link
Member

take

@nidhishtyagi
Copy link

Hey, so I've changed the return type to Optional[FrameOrSeriesUnion] but could you please explain what you mean by
overloading according to the value of inplace @MarcoGorelli

@MarcoGorelli
Copy link
Member Author

See set_axis and reset_index for examples - it looks like @DriesSchaumont is already working on this though

@DriesSchaumont
Copy link
Member

Yep, PR probably out tomorrow.

@MarcoGorelli
Copy link
Member Author

Awesome, feel free to ping if you get stuck on anything

@DriesSchaumont
Copy link
Member

@MarcoGorelli Did you mean that the return type is supposed to be FrameOrSeriesUnion | None or FrameOrSeries | None ? If I use FrameOrSeriesUnion, I get pandas/core/generic.py:7538: error: Incompatible return value type (got "FrameOrSeries", expected "Optional[Union[DataFrame, Series]]") [return-value] On line 7526, result = self. So FrameOrSeries seems applicable here?

@MarcoGorelli
Copy link
Member Author

My bad, I meant FrameOrSeries - thanks @DriesSchaumont !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants