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

BUG: Concat typing #36409

Merged
merged 3 commits into from
Sep 19, 2020
Merged

BUG: Concat typing #36409

merged 3 commits into from
Sep 19, 2020

Conversation

rhshadrach
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

cc @simonjayhawkins

Attempting to add typing to results in aggregation.transform. Here, the obj can be a Series but the list passed into concat contain frames. mypy correctly identifies this as an issue, I think concat needs to be typed as FrameOrSeriesUnion for this purpose.

When I try just typing the function definition and not the overload, mypy complains:

error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]

so I've changed the type of the overload to FrameOrSeriesUnion as well. I don't believe this is any weaker than the current state because it is an overload.

@rhshadrach
Copy link
Member Author

mypy fails in the CI check here because concat is called within NDFrame, which is not included in FrameOrSeriesUnion. I think part of the issue might be some odd behavior I'm seeing with Mapping and mypy. Still working through it, marking as a draft.

@rhshadrach rhshadrach marked this pull request as draft September 17, 2020 00:08
@jreback jreback added the Typing type annotations, mypy/pyright type checking label Sep 17, 2020
@simonjayhawkins
Copy link
Member

simonjayhawkins commented Sep 17, 2020

@rhshadrach #30852 (review) might help with the backstory for this.

It is worth noting that FrameOrSeriesUnion reports errors if concat called from an abstract/base class. And FrameOrSeries is a typevar and hence is used to preserve types. Maybe just NDFrame is what you require?

@rhshadrach rhshadrach marked this pull request as ready for review September 17, 2020 20:55
@rhshadrach
Copy link
Member Author

Thanks @simonjayhawkins, I've updated the type-hints to use NDFrame. We don't want FrameOrSeriesUnion here because concat can be called from NDFrame and we don't want FrameOrSeries because the argument could be a list of both frames and series.

One other thing I'll note is that while trying to provide various overloads, I ran into this bug that seems to impact many uses of overload where the arguments are Mapping or Dict (among other things).

@WillAyd
Copy link
Member

WillAyd commented Sep 17, 2020

It is worth noting that FrameOrSeriesUnion reports errors if concat called from an abstract/base class

Unrelated to this PR but what is the point of FrameOrSeriesUnion vs just using NDFrame? Just more user-friendly from an API perspective right?

@simonjayhawkins
Copy link
Member

simonjayhawkins commented Sep 18, 2020

It is worth noting that FrameOrSeriesUnion reports errors if concat called from an abstract/base class

Unrelated to this PR but what is the point of FrameOrSeriesUnion vs just using NDFrame? Just more user-friendly from an API perspective right?

@WillAyd the naming was decided in #30582. Looking back through the PR I think both of us prefered a FrameOrSeries and FrameOrSeriesT naming convention. That's also reason I closed #36100. I didn't want to propagate the current naming convention. #36100 (comment)

and I think somewhere in the history before that it was prefered to not have NDFrame in type annotations that might be visible to end users.

I'm +1 on NDFrame and NDFrameT where more appropriate.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm

@jreback jreback added this to the 1.2 milestone Sep 18, 2020
@jreback
Copy link
Contributor

jreback commented Sep 18, 2020

didn't we decide that NDFrame is confusing?

so am confused by

@WillAyd the naming was decided in #30582. Looking back through the PR I think both of us prefered a FrameOrSeries and FrameOrSeriesT naming convention. That's also reason I closed #36100. I didn't want to propagate the current naming convention. #36100 (comment)

@WillAyd you are now +1 on this?

@WillAyd
Copy link
Member

WillAyd commented Sep 19, 2020

Within the scope of this PR I think it make sense to not try and use the Union type of two objects in the parent.

Probably fine to have that Union from an API perspective but doesn't need to be forced internally

@jreback jreback merged commit 20ee6d2 into pandas-dev:master Sep 19, 2020
@jreback
Copy link
Contributor

jreback commented Sep 19, 2020

ok then,

should clarify in _typing on what should be used when for these types.

@rhshadrach rhshadrach deleted the concat_typing branch September 19, 2020 11:37
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
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.

4 participants