Skip to content

Commit 0a2d514

Browse files
committed
Fixup some test changes now that order is maintained
1 parent f144db2 commit 0a2d514

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

pandas/core/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ def is_dtype_equal(self, other):
19641964
"""
19651965

19661966
try:
1967-
return self.dtype is other.dtype
1967+
return hash(self.dtype) == hash(other.dtype)
19681968
except (AttributeError, TypeError):
19691969
return False
19701970

pandas/tests/test_categorical.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ def test_is_equal_dtype(self):
141141
c2 = Categorical(list('aabca'), categories=list('cab'), ordered=False)
142142
c3 = Categorical(list('aabca'), categories=list('cab'), ordered=True)
143143
assert c1.is_dtype_equal(c1)
144-
assert c2.is_dtype_equal(c2) # XXX: changed
144+
assert c2.is_dtype_equal(c2)
145145
assert c3.is_dtype_equal(c3)
146+
assert c1.is_dtype_equal(c2)
146147
assert not c1.is_dtype_equal(c3)
147148
assert not c1.is_dtype_equal(Index(list('aabca')))
148149
assert not c1.is_dtype_equal(c1.astype(object))
@@ -191,11 +192,8 @@ def f():
191192

192193
c1 = Categorical(["a", "b", "c", "a"], categories=["a", "c", "b"])
193194
c2 = Categorical(c1, categories=["a", "b", "c"])
194-
# XXX: change
195-
# tm.assert_numpy_array_equal(c1.__array__(), c2.__array__())
196-
assert set(c2.categories) == {'a', 'b', 'c'}
197-
# XXX: change
198-
# tm.assert_index_equal(c2.categories, Index(["a", "b", "c"]))
195+
tm.assert_numpy_array_equal(c1.__array__(), c2.__array__())
196+
tm.assert_index_equal(c2.categories, Index(["a", "b", "c"]))
199197

200198
# Series of dtype category
201199
c1 = Categorical(["a", "b", "c", "a"], categories=["a", "b", "c", "d"])
@@ -814,14 +812,12 @@ def test_construction_with_ordered(self):
814812
def test_ordered_api(self):
815813
# GH 9347
816814
cat1 = pd.Categorical(["a", "c", "b"], ordered=False)
817-
# XXX: changed
818-
assert set(cat1.categories) == {'a', 'b', 'c'}
815+
tm.assert_index_equal(cat1.categories, Index(['a', 'b', 'c']))
819816
assert not cat1.ordered
820817

821818
cat2 = pd.Categorical(["a", "c", "b"], categories=['b', 'c', 'a'],
822819
ordered=False)
823-
# XXX: changed
824-
assert set(cat1.categories) == {'a', 'b', 'c'}
820+
tm.assert_index_equal(cat2.categories, Index(['b', 'c', 'a']))
825821
assert not cat2.ordered
826822

827823
cat3 = pd.Categorical(["a", "c", "b"], ordered=True)
@@ -1224,8 +1220,7 @@ def test_unique(self):
12241220
categories=["a", "b", "c"])
12251221
exp = Index(["c", "a", "b"])
12261222
res = cat.unique()
1227-
# XXX: changed
1228-
assert set(res.categories) == set(exp)
1223+
tm.assert_index_equal(res.categories, exp)
12291224
exp_cat = Categorical(exp, categories=['c', 'a', 'b'])
12301225
tm.assert_categorical_equal(res, exp_cat)
12311226

0 commit comments

Comments
 (0)