ENH: Support rename on MultiIndex · Issue #4628 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Change up MultiIndex.rename
to be an alias for MultiIndex.set_names
.
Index.rename
: takes single objectMultiIndex.set_names
,Index.set_names
- same type signature: take list of names [Index.set_names can only take iterable of length 1)MultiIndex.rename
- synonym forset_names
So if you want to do something generically, you should use set_names
(just like you would with other attributes). If you expect a non-MI index, then you could use rename
with a string, etc.
cc @jreback
I personally think that this behavior is how it should work for Index. Everyone okay with this? I'd prefer not to do type sniffing if at all possible.
ind = Index(range(10)) ind.rename(["apple"], inplace=True) print(ind.name) # ['apple'] print(ind.names) # [['apple']] ind.set_names('apple') # Fails with error that it's too long