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

Categorical.__setitem__ should allow setting a Categorical with same unordered categories #24142

Closed
TomAugspurger opened this issue Dec 7, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@TomAugspurger
Copy link
Contributor

commented Dec 7, 2018

We'd need to recode the source categorical's codes to the target's.

In [6]: a = pd.Categorical(['a', 'b'], categories=['b', 'a'])

In [7]: b = pd.Categorical(['a', 'b'], categories=['a', 'b'])

In [8]: a[[True, False]] = b[[True, False]]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-9693ad7c05cc> in <module>
----> 1 a[[True, False]] = b[[True, False]]

~/sandbox/pandas/pandas/core/arrays/categorical.py in __setitem__(self, key, value)
   2082         if isinstance(value, Categorical):
   2083             if not value.categories.equals(self.categories):
-> 2084                 raise ValueError("Cannot set a Categorical with another, "
   2085                                  "without identical categories")
   2086

ValueError: Cannot set a Categorical with another, without identical categories
@TomAugspurger

This comment has been minimized.

Copy link
Contributor Author

commented Dec 7, 2018

I may handle this in
#24114, since it's blocking a setitem-based where.

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

And does the where operation need to work with unequal categorical dtypes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.