Skip to content

TYP: fix hashable keys for pd.concat #46608

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

Merged
merged 2 commits into from
Apr 4, 2022
Merged

TYP: fix hashable keys for pd.concat #46608

merged 2 commits into from
Apr 4, 2022

Conversation

twoertwein
Copy link
Member

Could use Any but I think in this case the covariant TypeVar approach isn't ugly (I think so - happy to change to Any).

@twoertwein twoertwein requested a review from Dr-Irv April 2, 2022 02:17
Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I'm still wary about using HashableT as a key in Mapping, but I can't find a case where it doesn't work.

@twoertwein
Copy link
Member Author

I'm still wary about using HashableT as a key in Mapping, but I can't find a case where it doesn't work.

Was about to change it to Any but then mypy seems to complain about overlapping overloads (either something wrong with my setup or a mypy bug?)

pandas/core/reshape/concat.py:65: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc]

@jreback jreback added the Typing type annotations, mypy/pyright type checking label Apr 4, 2022
@jreback jreback added this to the 1.5 milestone Apr 4, 2022
@jreback jreback merged commit 0141d92 into pandas-dev:main Apr 4, 2022
@Dr-Irv
Copy link
Contributor

Dr-Irv commented Apr 6, 2022

Was about to change it to Any but then mypy seems to complain about overlapping overloads (either something wrong with my setup or a mypy bug?)

It's neither. The issue here is that Mapping[Any, DataFrame] intersects Iterable[Series] . Something that matches Mapping[Series, DataFrame] also matches Iterable[Series] and Mapping[Any, DataFrame] , so you get the overlapping return types because there is an intersection in the type of the objs parameter.

@twoertwein
Copy link
Member Author

Thank you for finding this @Dr-Irv! I guess it works with TypeVars because Series/DataFrame are not Hashable.

@twoertwein twoertwein deleted the concat branch May 26, 2022 01:59
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
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