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

str.cat inconsistent for CategoricalIndex #20842

Closed
h-vetinari opened this issue Apr 27, 2018 · 2 comments · Fixed by #20347
Closed

str.cat inconsistent for CategoricalIndex #20842

h-vetinari opened this issue Apr 27, 2018 · 2 comments · Fixed by #20347

Comments

@h-vetinari
Copy link
Contributor

The str.cat-accessor works for CategoricalIndex as target, but not as caller. This is inconsistent.

a = pd.Index(['a', 'b', 'a'])
b = pd.Index(['a', 'b', 'a'], dtype='category')
a.str.cat(b)
# Index(['aa', 'bb', 'aa'], dtype='object')
b.str.cat(a)
# AttributeError: Can only use .str accessor with string values (i.e. inferred_type is 'string', 'unicode' or 'mixed')
@WillAyd
Copy link
Member

WillAyd commented Apr 30, 2018

Why wouldn't you just rename your categories?

@h-vetinari
Copy link
Contributor Author

@WillAyd
this was just a toy example - if there's more to concatenate, it gets more unwieldy. But more than that, it makes no sense that a.str.cat(b) works, but b.str.cat(a) doesn't.

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

Successfully merging a pull request may close this issue.

2 participants