Skip to content

Commit 2581275

Browse files
committed
simplify the fix, add issue reference number to corresponding test and tighten the wording in doc whatsnew
1 parent da692c1 commit 2581275

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

doc/source/whatsnew/v0.21.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Numeric
130130
Categorical
131131
^^^^^^^^^^^
132132

133-
- Bug in ``Categorical.is_dtype_equal()`` where comparison with Series whose dtype is 'category' is not handled correctly (:issue:`16659`)
133+
- Bug in ``Categorical.is_dtype_equal()`` where comparison with a Series with dtype='category' (:issue:`16659`)
134134

135135

136136
Other

pandas/core/categorical.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2005,12 +2005,10 @@ def is_dtype_equal(self, other):
20052005
from pandas.core.series import Series
20062006

20072007
if isinstance(other, Series):
2008-
other_categorical = other.values
2009-
else:
2010-
other_categorical = other
2008+
other = Categorical(other)
20112009

2012-
return (self.categories.equals(other_categorical.categories) and
2013-
self.ordered == other_categorical.ordered)
2010+
return (self.categories.equals(other.categories) and
2011+
self.ordered == other.ordered)
20142012
except (AttributeError, TypeError):
20152013
return False
20162014

pandas/tests/test_categorical.py

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def test_is_equal_dtype(self):
152152
CategoricalIndex(c1, categories=list('cab'))))
153153
assert not c1.is_dtype_equal(CategoricalIndex(c1, ordered=True))
154154

155+
# GH 16659
155156
s1 = pd.Series(c1)
156157
assert c1.is_dtype_equal(s1)
157158
assert not c2.is_dtype_equal(s1)

0 commit comments

Comments
 (0)