Skip to content

Commit 9a66dbb

Browse files
committed
Merge branch 'fix-datetime-categorical-comparison' of https://github.com/immerrr/pandas into immerrr-fix-datetime-categorical-comparison
Conflicts: doc/source/whatsnew/v0.15.1.txt
2 parents 387c9bf + 9ce9378 commit 9a66dbb

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

doc/source/whatsnew/v0.15.1.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Bug Fixes
157157
- Bug in coercing in astype of a ``Categorical`` of a passed ``pd.Categorical`` (this now raises ``TypeError`` correctly), (:issue:`8626`)
158158
- Bug in ``cut``/``qcut`` when using ``Series`` and ``retbins=True`` (:issue:`8589`)
159159
- Bug in writing Categorical columns to an SQL database with ``to_sql`` (:issue:`8624`).
160+
- Bug in comparing ``Categorical`` of datetime raising when being compared to a scalar datetime (:issue:`8687`)
160161

161162

162163

@@ -165,7 +166,8 @@ Bug Fixes
165166

166167

167168

168-
- Bug in numeric index operations of add/sub with Float/Index Index with numpy arrays (:issue:`8608`
169+
170+
- Bug in numeric index operations of add/sub with Float/Index Index with numpy arrays (:issue:`8608`)
169171
- Bug in setitem with empty indexer and unwanted coercion of dtypes (:issue:`8669`)
170172

171173

pandas/core/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from warnings import warn
55
import types
66

7-
from pandas import compat
7+
from pandas import compat, lib
88
from pandas.compat import u
99

1010
from pandas.core.algorithms import factorize
@@ -42,7 +42,7 @@ def f(self, other):
4242
# In other series, the leads to False, so do that here too
4343
ret[na_mask] = False
4444
return ret
45-
elif np.isscalar(other):
45+
elif lib.isscalar(other):
4646
if other in self.categories:
4747
i = self.categories.get_loc(other)
4848
return getattr(self._codes, op)(i)

pandas/tests/test_categorical.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,11 @@ def test_deprecated_levels(self):
912912

913913
self.assertFalse(LooseVersion(pd.__version__) >= '0.18')
914914

915+
def test_datetime_categorical_comparison(self):
916+
dt_cat = pd.Categorical(pd.date_range('2014-01-01', periods=3))
917+
self.assert_numpy_array_equal(dt_cat > dt_cat[0], [False, True, True])
918+
self.assert_numpy_array_equal(dt_cat[0] < dt_cat, [False, True, True])
919+
915920

916921
class TestCategoricalAsBlock(tm.TestCase):
917922
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)