BUG: fix Categorical comparison to work with datetime by immerrr · Pull Request #8687 · pandas-dev/pandas (original) (raw)

pd.Timestamp is one of types that don't pass np.isscalar test previously
used in _cat_compare_op, pd.lib.isscalar should be used instead.

In [1]: cat = pd.Categorical(pd.date_range('2014', periods=5))

In [2]: cat > cat[0]

TypeError Traceback (most recent call last) in () ----> 1 cat > cat[0]

/home/dshpektorov/sources/pandas/pandas/core/categorical.py in f(self, other) 52 msg = "Cannot compare a Categorical for op {op} with type {typ}. If you want to \n"
53 "compare values, use 'np.asarray(cat) other'." ---> 54 raise TypeError(msg.format(op=op,typ=type(other))) 55 56 f.name = op

TypeError: Cannot compare a Categorical for op gt with type <class 'pandas.tslib.Timestamp'>. If you want to compare values, use 'np.asarray(cat) other'.