API: relax categorical equality when comparing against object · Issue #8938 · pandas-dev/pandas (original) (raw)
from SO
In [1]: a = pd.Series(['a','b','c'],dtype="category")
In [2]: b = pd.Series(['a','b','c'],dtype="object")
In [3]: c = pd.Series(['a','b','cc'],dtype="object")
In [5]: a==b
TypeError: Cannot compare a Categorical for op <built-in function eq> with type <type 'numpy.ndarray'>. If you want to
compare values, use 'series <op> np.asarray(cat)'.
In [6]: A = pd.DataFrame({'A':a,'B':[1,2,3]})
In [7]: B = pd.DataFrame({'A':b,'C':[4,5,6]})
In [9]: A.merge(B,on='A')
Out[9]:
A B C
0 a 1 4
1 b 2 5
2 c 3 6
In [10]: A.merge(B,on='A').dtypes
Out[10]:
A object
B int64
C int64
dtype: object
In [11]: A.dtypes
Out[11]:
A category
B int64
dtype: object
In [12]: B.dtypes
Out[12]:
A object
C int64
dtype: object