pydata/pandas — pull request #3175 by waitingkuo (2013-03-25 19:12:07+00:00)
Title: BUG: Fix the rename function for Series and DataFrame, #3165

### Bug 1: After `rename`, the `name` of the `index` is missing:

In [1]: import pandas as pd

In [2]: data = [1, 2]

In [3]: index = pd.Index(['a', 'b'], name='name')

In [4]: df = pd.DataFrame(data, index=index)

In [5]: df
Out[5]:
0
name
a 1
b 2

In [6]: df.rename({'a': 'c'})
Out[6]:
0
c 1
b 2

Both `Series` and `DataFrame` has the same problems. The reason is that we didn't set the `name` of the `index` while reconstructing the `DataFrame/Series` by `rename` .

### Bug 2: `rename` cannot work for the `MultiIndex` case, the `index` becomes tuples, the `names` of the index are gone

In [1]: import pandas as pd

In [2]: data = [1, 2]

In [3]: index = pd.MultiIndex.from_tuples([('a', 'b'), ('c', 'd')], names=['name1', 'name2'])

In [4]: df = pd.DataFrame(data, index=index)

In [5]: df
Out[5]:
0
name1 name2
a b 1
c d 2

In [6]: df.rename({'a': 'e'})
Out[6]:
0
(a, b) 1
(c, d) 2

The missing name issue is same as Bug1. The original `rename` function convert the dict to the mapper function and map each tuple but not each index, and doesn't reconstruct it as `MultiIndex`, so it becomes a `Index` with some tuples.

### Fix

I've fixed the above two bugs, the `rename` will also pass the `name` of the `index` too, the `rename` mapper will go through each index for the `MultiIndex` case now.
I also added some test cases in `test_series.py` and `test_frame.py`