Skip to content

ENH: Allow map with abc mapping #29788

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 19 commits into from
Jan 2, 2020

Conversation

ohad83
Copy link
Contributor

@ohad83 ohad83 commented Nov 22, 2019

@ohad83 ohad83 changed the title Bug allow map with abc mapping BUG - allow map with abc mapping Nov 22, 2019
ohad83 added a commit to ohad83/pandas that referenced this pull request Nov 22, 2019
@gfyoung gfyoung added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Series Series data structure Enhancement labels Nov 22, 2019
@gfyoung gfyoung changed the title BUG - allow map with abc mapping ENH: Allow map with abc mapping Nov 22, 2019
@ohad83 ohad83 force-pushed the BUG-allow-map-with-abc-mapping branch from 7df89d3 to dadb76a Compare November 22, 2019 12:47
@ohad83 ohad83 marked this pull request as ready for review November 22, 2019 13:20
@ohad83 ohad83 requested a review from jreback November 22, 2019 14:25
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.

Looks good generally. cc @TomAugspurger and @simonjayhawkins for related discussions that we've had on types - not sure if this is something we would need to review holistically

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Nov 22, 2019 via email

@ohad83
Copy link
Contributor Author

ohad83 commented Nov 23, 2019

Changes here look sensible. It's not immediately clear to my why Series.__init__ had to change. Can we add a test in pandas/tests/series/test_constructors.py that shows the change? We may want to move these Mapping subclass test helpers to a central place and reuse them.

Added a test for constructing a Series with NonDictMapping and moved the NonDictMapping test subclass to pandas/util/testing.py.

@ohad83 ohad83 requested a review from WillAyd November 24, 2019 21:30
@@ -253,7 +254,7 @@ def __init__(
else:
data = data.reindex(index, copy=copy)
data = data._data
elif isinstance(data, dict):
elif isinstance(data, abc.Mapping):
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use is_dict_like here instead

@@ -1215,8 +1215,8 @@ def _map_values(self, mapper, na_action=None):
# we can fastpath dict/Series to an efficient map
# as we know that we are not going to have to yield
# python types
if isinstance(mapper, dict):
if hasattr(mapper, "__missing__"):
if isinstance(mapper, abc.Mapping):
Copy link
Contributor

Choose a reason for hiding this comment

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

use is_dict_like

@jreback jreback added this to the 1.0 milestone Dec 8, 2019
@jreback
Copy link
Contributor

jreback commented Dec 8, 2019

lgtm. ping on green.

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. @ohad83 can you merge master one more time? I think should get CI green

@ohad83
Copy link
Contributor Author

ohad83 commented Dec 9, 2019

@WillAyd Merged but still a test seems to fail, I am not really sure what's happening and how, if at all, it's related to this PR.. Any ideas?

@ohad83 ohad83 force-pushed the BUG-allow-map-with-abc-mapping branch from 55a1dfa to 5c6bb3c Compare December 14, 2019 10:03
@ohad83
Copy link
Contributor Author

ohad83 commented Dec 14, 2019

lgtm. @ohad83 can you merge master one more time? I think should get CI green

@jreback @WillAyd It's green now

@@ -2121,6 +2121,20 @@ def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)


class TestNonDictMapping(abc.Mapping):
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this a fixture in pandas/tests/series/conftest.py instead of putting in pandas.util.testing? With the latter sometimes things can leak into our API and definitely wouldn't want that here

@jbrockmendel
Copy link
Member

@ohad83 can you rebase and address Will's comment if still relevant

@jreback
Copy link
Contributor

jreback commented Dec 27, 2019

can you merge master and will look again

@jreback
Copy link
Contributor

jreback commented Jan 1, 2020

@ohad83 going to have this close the original issue. if the remaining case is worthile, then pls open a new issue.

@jreback jreback force-pushed the BUG-allow-map-with-abc-mapping branch from 1f7d650 to 97d245d Compare January 1, 2020 17:13
@jreback
Copy link
Contributor

jreback commented Jan 1, 2020

@WillAyd if any comments

@WillAyd WillAyd merged commit d47c5a2 into pandas-dev:master Jan 2, 2020
@WillAyd
Copy link
Member

WillAyd commented Jan 2, 2020

Thanks @ohad83 great PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Enhancement Series Series data structure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.map(m: Mapping) can fail with "object is not callable"
7 participants