Skip to content

Commit cc624ed

Browse files
committed
simpler cleanup
1 parent 9fd4ee7 commit cc624ed

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/_testing/asserters.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,18 @@ def _check_types(left, right, obj="Index") -> None:
314314
return
315315

316316
assert_class_equal(left, right, exact=exact, obj=obj)
317-
assert_attr_equal("inferred_type", left, right, obj=obj)
318-
assert_attr_equal("dtype", left, right, obj=obj)
319317

320318
# Skip exact dtype checking when `check_categorical` is False
321-
if (
322-
check_categorical
323-
and is_categorical_dtype(left.dtype)
324-
and is_categorical_dtype(right.dtype)
325-
):
326-
assert_index_equal(left.categories, right.categories, exact=exact)
319+
if check_categorical:
320+
assert_attr_equal("dtype", left, right, obj=obj)
321+
if is_categorical_dtype(left.dtype) and is_categorical_dtype(right.dtype):
322+
assert_index_equal(left.categories, right.categories, exact=exact)
323+
324+
# allow string-like to have different inferred_types
325+
if left.inferred_type in ("string"):
326+
assert right.inferred_type in ("string")
327+
else:
328+
assert_attr_equal("inferred_type", left, right, obj=obj)
327329

328330
def _get_ilevel_values(index, level):
329331
# accept level number only

0 commit comments

Comments
 (0)