@@ -314,18 +314,16 @@ def _check_types(left, right, obj="Index") -> None:
314
314
return
315
315
316
316
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 )
317
319
318
320
# 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 )
329
327
330
328
def _get_ilevel_values (index , level ):
331
329
# accept level number only
@@ -446,17 +444,18 @@ def repr_class(x):
446
444
447
445
return type (x ).__name__
448
446
447
+ if type (left ) == type (right ):
448
+ return
449
+
449
450
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"
459
455
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 ))
460
459
461
460
462
461
def assert_attr_equal (attr : str , left , right , obj : str = "Attributes" ):
0 commit comments