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

TYP: Fix typing of frame.explode #43834

Merged
merged 2 commits into from
Oct 1, 2021
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Oct 1, 2021

@phofl phofl added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Typing type annotations, mypy/pyright type checking labels Oct 1, 2021
@phofl phofl added this to the 1.3.4 milestone Oct 1, 2021
@@ -8201,7 +8201,7 @@ def stack(self, level: Level = -1, dropna: bool = True):

def explode(
self,
column: Scalar | tuple | list[Scalar | tuple],
column: IndexLabel | tuple,
Copy link
Member

Choose a reason for hiding this comment

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

tuple is hashable so can remove that too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm forgot that.Thx

Copy link
Member Author

Choose a reason for hiding this comment

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

@simonjayhawkins got a follow up question: IndexLabel does include Series, DataFrame and arrays? So I think I misunderstood you in the other pr? We should annotate this with Hashable| tuple | list[Hashable| tuple] not IndexLabel, because arrays and so on are not allowed here

Copy link
Member

Choose a reason for hiding this comment

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

IndexLabel does not yet include Series, DataFrame, Index, EAs etc since they do not satisfy typing.Seqence

For public methods, the function should be as permissible as possible and consistent with other methods accepting similar parameters.

If explode is more restrictive than other methods that accept a columns parameter, we should probably fix. (and maybe should not use the IndexLabel alias yet)

Copy link
Member Author

Choose a reason for hiding this comment

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

So we should use IndexLabel always when we have a single column or a list of columns if possible? And when we have only a single column Hashable would be appropriate?

Copy link
Member

Choose a reason for hiding this comment

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

yes for consistency in public methods. but the types should also reflect the types accepted by the method so where we have discrepancies, mypy should hightlight this as we add more types. Typing of the public api is more difficult, especially since we don't have many of the lower level functions typed.

for internal methods we can be less permissive and say only pass a list around. (The issue then becomes that the list is mutable, so function code could unintentionally change the contents and mypy would catch that.)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes of course, if its more strict we should define that. Thanks for the explanation, this helps a lot.

@jreback jreback merged commit 4f15df2 into pandas-dev:master Oct 1, 2021
@jreback
Copy link
Contributor

jreback commented Oct 1, 2021

@meeseeksdev backport 1.3.x

@lumberbot-app
Copy link

lumberbot-app bot commented Oct 1, 2021

Something went wrong ... Please have a look at my logs.

jreback pushed a commit that referenced this pull request Oct 1, 2021
Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
@simonjayhawkins
Copy link
Member

Thanks @phofl for the quick follow-up. backporting typing PRs is not necessary.

gasparitiago pushed a commit to gasparitiago/pandas that referenced this pull request Oct 9, 2021
@phofl phofl deleted the typ_explode branch November 13, 2021 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants