Skip to content

Commit 2fb416d

Browse files
committed
simplify the fix, add issue reference number to corresponding test and tighten the wording in doc whatsnew
1 parent 556f9c3 commit 2fb416d

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
@@ -304,7 +304,7 @@ Categorical
304304
^^^^^^^^^^^
305305
- Bug in :func:`Series.isin` when called with a categorical (:issue`16639`)
306306

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

309309

310310
Other

pandas/core/categorical.py

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

19771977
if isinstance(other, Series):
1978-
other_categorical = other.values
1979-
else:
1980-
other_categorical = other
1978+
other = Categorical(other)
19811979

1982-
return (self.categories.equals(other_categorical.categories) and
1983-
self.ordered == other_categorical.ordered)
1980+
return (self.categories.equals(other.categories) and
1981+
self.ordered == other.ordered)
19841982
except (AttributeError, TypeError):
19851983
return False
19861984

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)