Skip to content

Commit 7bf25de

Browse files
committed
CLN: assert_index_equal & assert_class_equal
1 parent 52f04db commit 7bf25de

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

pandas/_testing/asserters.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,16 @@ 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("dtype", left, right, obj=obj)
318+
assert_attr_equal("inferred_type", left, right, obj=obj)
317319

318320
# Skip exact dtype checking when `check_categorical` is False
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)
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)
329327

330328
def _get_ilevel_values(index, level):
331329
# accept level number only
@@ -446,17 +444,18 @@ def repr_class(x):
446444

447445
return type(x).__name__
448446

447+
if type(left) == type(right):
448+
return
449+
449450
if exact == "equiv":
450-
if type(left) != type(right):
451-
# allow equivalence of Int64Index/RangeIndex
452-
types = {type(left).__name__, type(right).__name__}
453-
if len(types - {"Int64Index", "RangeIndex"}):
454-
msg = f"{obj} classes are not equivalent"
455-
raise_assert_detail(obj, msg, repr_class(left), repr_class(right))
456-
elif exact:
457-
if type(left) != type(right):
458-
msg = f"{obj} classes are different"
451+
# allow equivalence of Int64Index/RangeIndex
452+
types = {type(left).__name__, type(right).__name__}
453+
if len(types - {"Int64Index", "RangeIndex"}):
454+
msg = f"{obj} classes are not equivalent"
459455
raise_assert_detail(obj, msg, repr_class(left), repr_class(right))
456+
elif exact:
457+
msg = f"{obj} classes are different"
458+
raise_assert_detail(obj, msg, repr_class(left), repr_class(right))
460459

461460

462461
def assert_attr_equal(attr: str, left, right, obj: str = "Attributes"):

0 commit comments

Comments
 (0)