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

DataFrame indices can't map through dictionaries or series #12756

Closed
azevedoph-check24 opened this issue Mar 31, 2016 · 3 comments · Fixed by #15081
Closed

DataFrame indices can't map through dictionaries or series #12756

azevedoph-check24 opened this issue Mar 31, 2016 · 3 comments · Fixed by #15081
Labels
API Design Clean Internals Related to non-user accessible pandas implementation Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@azevedoph-check24
Copy link

A DataFrame index has the map function, which expects a mapper. However, unlike mapping a Series, it only accepts callables, and won't work when mapping through dictionaries or series.

Code Sample:

df = pd.DataFrame({'col1': range(5)})
d = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four'}
df.col1.map(d) # perfectly valid
df.index.map(d) # TypeError: 'dict' object is not callable
s = pd.Series(d)
df.col1.map(s) # perfectly valid
df.index.map(s) # TypeError: 'Series' object is not callable

Expected Output:

I would expect the same output for df.col1.map(s) and df.index.map(s), or at least that it returns an nparray with the mapped values, as it does when we do pass a callable, but not that it breaks like it does.

output of pd.show_versions():

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-67-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_DE.UTF-8

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 20.6.6
Cython: 0.23.5
numpy: 1.11.0
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 4.1.2
sphinx: 1.4
patsy: 0.4.1
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: 2.5.1
matplotlib: 1.5.1
openpyxl: 2.3.4
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: 3.6.0
bs4: None
html5lib: 0.9999999
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: 2.39.0

@jreback
Copy link
Contributor

jreback commented Mar 31, 2016

@sinhrks and I had this exact discussion very recently: #12532 (comment)

so yes, these should be unified, but are a bit non-trivial to do so. welcome to have pull-requests!

@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode API Design Internals Related to non-user accessible pandas implementation Difficulty Intermediate Clean labels Mar 31, 2016
@jreback jreback added this to the Next Major Release milestone Mar 31, 2016
@sinhrks
Copy link
Member

sinhrks commented Mar 31, 2016

Yes, currently I think Index.map should be fixed prior to #12532. Will take a look.

@jreback
Copy link
Contributor

jreback commented Apr 1, 2016

xref #12766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Clean Internals Related to non-user accessible pandas implementation Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants