Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Series.rename() ignores level argument on MultiIndex #5653

Closed
TomAugspurger opened this issue Dec 6, 2013 · 5 comments
Closed

BUG: Series.rename() ignores level argument on MultiIndex #5653

TomAugspurger opened this issue Dec 6, 2013 · 5 comments

Comments

@TomAugspurger
Copy link
Contributor

At least I think this is a bug. #4627 was meant to unify the Series and DataFrame.rename APIs right?

In [35]: idx = pd.MultiIndex.from_tuples([(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)])

In [36]: s = pd.Series(np.arange(6), index=idx)

In [37]: s
Out[37]: 
1  1    0
   2    1
   3    2
2  1    3
   2    4
   3    5
dtype: int64

In [38]: s.index.names = ['outer', 'inner']

In [39]: s.rena
s.rename       s.rename_axis  

In [39]: s.rename({1: 'L1', 2: 'L2', 3: 'L3'}, level='inner')
Out[39]: 
outer  inner
L1     L1       0
       L2       1
       L3       2
L2     L1       3
       L2       4
       L3       5
dtype: int64

Edit: I guess I'm a bit confused because the docstring seems to indicate that Series.rename() does something a bit different:

Conform Series to new index with optional filling logic, placing
NA/NaN in locations having no value in the previous index. A new object
is produced unless the new index is equivalent to the current one and
copy=False
@jreback
Copy link
Contributor

jreback commented Dec 6, 2013

closed via 5dde943

was picking up the wrong docstring

@jreback jreback closed this as completed Dec 6, 2013
@TomAugspurger
Copy link
Contributor Author

That was fast :) I thought my issue hadn't been created, but it was already closed.

But what about the levels argument? For

In [39]: s.rename({1: 'L1', 2: 'L2', 3: 'L3'}, level='inner')
Out[39]: 
outer  inner
L1     L1       0
       L2       1
       L3       2
L2     L1       3
       L2       4
       L3       5
dtype: int64

I think only the inner level should be renamed, not both.

@jreback
Copy link
Contributor

jreback commented Dec 6, 2013

doesn't take a level argument. IIRC their is an issue about this....

@TomAugspurger
Copy link
Contributor Author

OK, thanks. I'll see if I can track it down.

@jreback
Copy link
Contributor

jreback commented Dec 6, 2013

see #4160 and #4023 (may be somewhat duplicated issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants