Skip to content

Commit 9a30b86

Browse files
topper-123TomAugspurger
authored andcommitted
improve test output for Categoricals (#18069)
(cherry picked from commit bb4fa65)
1 parent 7dabfc6 commit 9a30b86

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

doc/source/whatsnew/v0.21.1.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ Categorical
119119
^^^^^^^^^^^
120120

121121
- Bug in :meth:`DataFrame.astype` where casting to 'category' on an empty ``DataFrame`` causes a segmentation fault (:issue:`18004`)
122-
-
122+
- Error messages in the testing module have been improved when items have
123+
different ``CategoricalDtype`` (:issue:`18069`)
123124
-
124125
- Error messages in the testing module have been improved when items have
125126
different ``CategoricalDtype`` (:issue:`18069`)

pandas/util/testing.py

+4
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,12 @@ def assert_categorical_equal(left, right, check_dtype=True,
10741074
def raise_assert_detail(obj, message, left, right, diff=None):
10751075
if isinstance(left, np.ndarray):
10761076
left = pprint_thing(left)
1077+
elif is_categorical_dtype(left):
1078+
left = repr(left)
10771079
if isinstance(right, np.ndarray):
10781080
right = pprint_thing(right)
1081+
elif is_categorical_dtype(right):
1082+
right = repr(right)
10791083

10801084
msg = """{obj} are different
10811085

0 commit comments

Comments
 (0)