@@ -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 ("inferred_type" , left , right , obj = obj )
317
318
318
319
# 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 ):
320
+ if is_categorical_dtype ( left . dtype ) and is_categorical_dtype ( right . dtype ) :
321
+ if check_categorical :
322
+ assert_attr_equal ( " dtype" , left , right , obj = obj )
322
323
assert_index_equal (left .categories , right .categories , exact = exact )
324
+ return
323
325
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 )
326
+ assert_attr_equal ("dtype" , left , right , obj = obj )
329
327
330
328
def _get_ilevel_values (index , level ):
331
329
# accept level number only
@@ -437,6 +435,8 @@ def assert_class_equal(left, right, exact: bool | str = True, obj="Input"):
437
435
"""
438
436
Checks classes are equal.
439
437
"""
438
+ from pandas .core .indexes .numeric import NumericIndex
439
+
440
440
__tracebackhide__ = True
441
441
442
442
def repr_class (x ):
@@ -446,17 +446,16 @@ def repr_class(x):
446
446
447
447
return type (x ).__name__
448
448
449
+ if type (left ) == type (right ):
450
+ return
451
+
449
452
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 ))
453
+ # accept equivalence of NumericIndex (sub-)classes
454
+ if isinstance (left , NumericIndex ) and isinstance (right , NumericIndex ):
455
+ return
456
+
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