ENH: Support rename on MultiIndex · Issue #4628 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@jtratner

Description

@jtratner

Change up MultiIndex.rename to be an alias for MultiIndex.set_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