-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Series.map(m: Mapping) can fail with "object is not callable" #29733
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
Comments
Hey @ivirshup,
Funnily enough, while Anyway, I see no harm in checking whether the object satisfies I'll create the pull request and let the maintainers decide whether it should go in. |
Can someone explain the benefit of allowing https://docs.python.org/3.8/library/collections.html#userdict-objects |
As I said I don't believe |
@gfyoung, the use case above was for when I wanted something like: |
Code Sample, a copy-pastable example if possible
Problem description
Series.map
can sometimes take Mapping subclasses other thandict
, but not always. I think it would make sense if any object that satisfiedisinstance(x, collections.abc.Mapping)
could be used as a mapping. I came across this while trying to use map where I only wanted values present as keys in the mapping to change (I went fors.map(lambda x: {"a": "b"}.get(x, x))
as a workaround).collections.Counter
andcollections.defaultdict
work fine, which made me expect otherMapping
s would as well.Expected Output
I expected
s.map(MissingDict({"a": "c"}))
to do something like:Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: