@@ -316,16 +316,15 @@ def _check_types(left, right, obj="Index") -> None:
316
316
assert_class_equal (left , right , exact = exact , obj = obj )
317
317
318
318
# 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 ):
319
+ if is_categorical_dtype ( left . dtype ) and is_categorical_dtype ( right . dtype ) :
320
+ if check_categorical :
321
+ assert_attr_equal ( " dtype" , left , right , obj = obj )
322
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
323
assert_attr_equal ("inferred_type" , left , right , obj = obj )
324
+ return
325
+
326
+ assert_attr_equal ("inferred_type" , left , right , obj = obj )
327
+ assert_attr_equal ("dtype" , left , right , obj = obj )
329
328
330
329
def _get_ilevel_values (index , level ):
331
330
# accept level number only
@@ -437,6 +436,8 @@ def assert_class_equal(left, right, exact: bool | str = True, obj="Input"):
437
436
"""
438
437
Checks classes are equal.
439
438
"""
439
+ from pandas .core .indexes .numeric import NumericIndex
440
+
440
441
__tracebackhide__ = True
441
442
442
443
def repr_class (x ):
@@ -446,17 +447,16 @@ def repr_class(x):
446
447
447
448
return type (x ).__name__
448
449
450
+ if type (left ) == type (right ):
451
+ return
452
+
449
453
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"
459
- raise_assert_detail (obj , msg , repr_class (left ), repr_class (right ))
454
+ # accept equivalence of NumericIndex (sub-)classes
455
+ if isinstance (left , NumericIndex ) and isinstance (right , NumericIndex ):
456
+ return
457
+
458
+ msg = f"{ obj } classes are different"
459
+ raise_assert_detail (obj , msg , repr_class (left ), repr_class (right ))
460
460
461
461
462
462
def assert_attr_equal (attr : str , left , right , obj : str = "Attributes" ):
0 commit comments