Skip to content

TYP: use overload to refine return type of reset_index #33519

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

Conversation

simonjayhawkins
Copy link
Member

No description provided.

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Apr 13, 2020
self,
level: Optional[Union[Hashable, Sequence[Hashable]]] = None,
drop: bool = False,
*,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to combine Literal and overload here instead of this? I don’t think this is 100% accurate if a user provides inplace=False

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't use Literal til Python 3.8 or unless we adopt typing extensions.

If we pass inplace=False the return type will match the second signature and so the return type will be the Union. This is not inaccurate and no change from the status quo.

If we don't pass an inplace argument, the return type will be DataFrame and additional asserts, casts or ignores aren't needed. This is an improvement from the status quo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether explicitly passing inplace=False or just sticking with the default signature the expected return type shouldn't be different, which is what is being introduced here. The ideal overload should be something like "return None if inplace=True, otherwise return a DataFrame".

While the current approach may appease most type checking it introduces unexpected behavior when providing the inplace keyword; would rather try to integrate a Literal type or actually deprecate inplace.

self,
level: Optional[Union[Hashable, Sequence[Hashable]]] = None,
drop: bool = False,
*,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether explicitly passing inplace=False or just sticking with the default signature the expected return type shouldn't be different, which is what is being introduced here. The ideal overload should be something like "return None if inplace=True, otherwise return a DataFrame".

While the current approach may appease most type checking it introduces unexpected behavior when providing the inplace keyword; would rather try to integrate a Literal type or actually deprecate inplace.

@simonjayhawkins
Copy link
Member Author

would rather try to integrate a Literal type

can't use Literal yet.

or actually deprecate inplace.

can't do this till 2.0

closing to clear queue as requested changes not actionable. can potentially reopen depending on outcome of #33274

@simonjayhawkins
Copy link
Member Author

closing to clear queue as requested changes not actionable. can potentially reopen depending on outcome of #33274

reopening as #33274 is closed.

would rather try to integrate a Literal type

Literal types are not an option for this PR at this stage.

@jbrockmendel
Copy link
Member

@simonjayhawkins @WillAyd is there a consensus on how to move forward here?

@WillAyd
Copy link
Member

WillAyd commented Apr 27, 2020

So I wouldn't object to vendoring typing_extensions and doing this with Literal values - @simonjayhawkins do you have any particular thoughts on that?

As is though I think this creates as many nuances as it solves, so not a huge fan of going forward in current state

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

Successfully merging this pull request may close these issues.

3 participants