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 treats Series as list-like instead of mapping #12623

Closed
TomAugspurger opened this issue Mar 14, 2016 · 4 comments
Closed

BUG: Series.rename treats Series as list-like instead of mapping #12623

TomAugspurger opened this issue Mar 14, 2016 · 4 comments
Labels
Milestone

Comments

@TomAugspurger
Copy link
Contributor

#### Code Sample, a copy-pastable example if possible

In [6]: s = pd.Series([0, 1])

In [5]: s.rename(pd.Series({0: 10, 1: 20}))
Out[5]:
0    0
1    1
Name: [10, 20], dtype: int64

Problem is here using an isinstance(,MutableMapping) instead of com.is_dict_like. rename_axis should be fine, but will add tests for both.

@jreback
Copy link
Contributor

jreback commented Mar 14, 2016

Indexes are NOT dict_like though (Series ARE). so something else happening.

In [3]: pandas.core.common.is_dict_like(pd.RangeIndex(10))
Out[3]: False

In [4]: pandas.core.common.is_dict_like(pd.Index([1,2,3]))
Out[4]: False

@TomAugspurger
Copy link
Contributor Author

Ah.... my bad. I thought I didn't reproduce it with a non-RangeIndexed series, but I must have been mistaken.

In [52]: s.rename(pd.Series({'a': 'A', 'b': 'B'}))
Out[52]:
a    0
b    1
Name: [A, B], dtype: int64

I'll update.

@jreback
Copy link
Contributor

jreback commented Mar 14, 2016

somewhat related to #12610 (IOW setting the .name with a list should just fail), but you don't need to explicity check for this (well, you do but for a different reason, namely that you are doing something different with it)

@TomAugspurger TomAugspurger changed the title com.is_dict_like fails to treat RangeIndex as a mapper BUG: Series.rename treats Series as list-like instead of mapping Mar 14, 2016
@TomAugspurger
Copy link
Contributor Author

Updated, can't believe I missed this. Will have a fix tonight.

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Mar 15, 2016
Closes pandas-dev#12623

I added com.is_dict_like in pandas-dev#11980
and failed to use it for the `rename` method. Using that now and did
some refactoring while I was in there. Added more tests for rename.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants