Skip to content

Inconsistent behaviour of rename for MultiIndexed DataFrames and Series #4605

Closed
@alefnula

Description

@alefnula

If I try to rename a MultiIndexed DataFrame, everything works correctly:

In [3]: pd.DataFrame([11,21,31],
            index=pd.MultiIndex.from_tuples([("A",x) for x in ["a","B","c"]])).rename(str.lower)
Out[3]: 
      0
a a  11
  b  21
  c  31

But if I do the same thing with the Series, it doesn't work:

In [4]: pd.Series([11,21,31],
            index=pd.MultiIndex.from_tuples([("A",x) for x in ["a","B","c"]])).rename(str.lower)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-aa25b537c1df> in <module>()
----> 1 pd.Series([11,21,31],index=pd.MultiIndex.from_tuples([("A",x) for x in ["a","B","c"]])).rename(str.lower)

/home/viktor/pandas/pandas/core/series.py in rename(self, mapper, inplace)
   3187         result = self if inplace else self.copy()
   3188         result.index = Index([mapper_f(x)
-> 3189                              for x in self.index], name=self.index.name)
   3190 
   3191         if not inplace:

TypeError: descriptor 'lower' requires a 'str' object but received a 'tuple'

This behavior is observed in 0.12 and in the master branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignBugInternalsRelated to non-user accessible pandas implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions