ENH: Support rename on MultiIndex (original) (raw)
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