Fix for unequal comparisons of categorical and scalar by jankatins · Pull Request #9848 · pandas-dev/pandas (original) (raw)
I'll paste this here, just ran into this on CategoricalIndex
(this is with current impl)
In [2]: df = DataFrame({'A' : np.arange(6,dtype='int64'),
'B' : Series([1,1,2,1,3,2]).astype('category',categories=[3,2,1],ordered=True) }).set_index('B')
In [3]: df
Out[3]:
A
B
1 0
1 1
2 2
1 3
3 4
2 5
In [4]: df.index
Out[4]:
CategoricalIndex([1, 1, 2, 1, 3, 2],
categories=[3, 2, 1],
ordered=True,
name=u'B')
In [5]: df[df.index==1]
Out[5]:
A
B
1 0
1 1
1 3
In [6]: df[df.index>1]
Out[6]:
Empty DataFrame
Columns: [A]
Index: []
In [7]: df[df.index<1]
Out[7]:
A
B
2 2
3 4
2 5