Skip to content

BUG: fix Categorical comparison to work with datetime #8687

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

Merged

Conversation

immerrr
Copy link
Contributor

@immerrr immerrr commented Oct 30, 2014

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)
<ipython-input-2-77883e4783fe> in <module>()
----> 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) <op> 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) <op> other'.

@jreback
Copy link
Contributor

jreback commented Oct 30, 2014

can u add a simple doc note ref this pr

@immerrr
Copy link
Contributor Author

immerrr commented Oct 30, 2014

Ah, indeed, I've forgotten about that.

@jreback jreback added Categorical Categorical Data Type Bug labels Oct 30, 2014
@jreback jreback added this to the 0.15.1 milestone Oct 30, 2014
pd.Timestamp is one of types that don't pass np.isscalar test, that was
previously used in _cat_compare_op.  pd.lib.isscalar should be used
instead.
@immerrr immerrr force-pushed the fix-datetime-categorical-comparison branch from 8d088b3 to 9ce9378 Compare October 31, 2014 10:19
@jreback jreback merged commit 9ce9378 into pandas-dev:master Oct 31, 2014
@jreback
Copy link
Contributor

jreback commented Oct 31, 2014

thanks!

@immerrr immerrr deleted the fix-datetime-categorical-comparison branch November 2, 2014 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants