Skip to content

Renaming MultiIndex values does not work at all (doesn't update values, or raise an exception) #16008

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

Closed
gregsifr opened this issue Apr 15, 2017 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@gregsifr
Copy link

gregsifr commented Apr 15, 2017

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
df.set_index(['Last','First'], inplace=True)

# rename1
df.rename(index={('C','A'):('C','NEWFIRST')})

# rename2
df.rename(index={('C','A'):('NEWLAST','A')})

Problem description

Renaming Muiltiindex values does nothing, not even raise an Exception.

Expected Output

rename1 = pd.DataFrame({'First': ['NEWFIRST', 'A', 'A', 'B', 'B'], 'Last': ['C', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename1.set_index(['Last','First'], inplace=True)

rename2 = pd.DataFrame({'First': ['A', 'A', 'A', 'B', 'B'], 'Last': ['NEWLAST', 'D', 'E', 'E', 'F'], 'C':[1, 1, 2, 1, 1]})
rename2.set_index(['Last','First'], inplace=True)

Output of pd.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.8.0-46-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_AU.UTF-8 LOCALE: en_AU.UTF-8

pandas: 0.19.2+0.g825876c.dirty
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.1.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.4.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.6
lxml: None
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.4
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: 2.45.0
pandas_datareader: None

</details>
@jorisvandenbossche jorisvandenbossche added the Duplicate Report Duplicate issue or pull request label Apr 15, 2017
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Apr 15, 2017
@jorisvandenbossche
Copy link
Member

@gregsifr Thanks for the report.
This is currently a known limitation of rename, see #4160 (therefore closing this issue as a duplicate).

After #13766 it will be possible to rename values in a specific level only, but that is of course not yet what is raised here.

Currenlty rename works by trying to rename individual labels of the different levels, hence the dict with tuples (as in your example) have no effect as they are not found.
If we want to add this, we have to think about how the API could look like, or if there would be ambiguous cases if we try to infer that tuples are passed when having a MutliIndex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants