@@ -316,17 +316,22 @@ 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 not check_categorical :
321
+ assert_attr_equal ( " dtype" , left , right , obj = obj )
322
322
assert_index_equal (left .categories , right .categories , exact = exact )
323
+ else :
324
+ assert_attr_equal ("inferred_type" , left , right , obj = obj )
325
+ return
323
326
324
327
# allow string-like to have different inferred_types
325
328
if left .inferred_type in ("string" ):
326
329
assert right .inferred_type in ("string" )
327
330
else :
328
331
assert_attr_equal ("inferred_type" , left , right , obj = obj )
329
332
333
+ assert_attr_equal ("dtype" , left , right , obj = obj )
334
+
330
335
def _get_ilevel_values (index , level ):
331
336
# accept level number only
332
337
unique = index .levels [level ]
@@ -437,6 +442,8 @@ def assert_class_equal(left, right, exact: bool | str = True, obj="Input"):
437
442
"""
438
443
Checks classes are equal.
439
444
"""
445
+ from pandas .core .indexes .numeric import NumericIndex
446
+
440
447
__tracebackhide__ = True
441
448
442
449
def repr_class (x ):
@@ -450,14 +457,12 @@ def repr_class(x):
450
457
return
451
458
452
459
if exact == "equiv" :
453
- # allow equivalence of Int64Index/RangeIndex
454
- types = {type (left ).__name__ , type (right ).__name__ }
455
- if len (types - {"Int64Index" , "RangeIndex" }):
456
- msg = f"{ obj } classes are not equivalent"
457
- raise_assert_detail (obj , msg , repr_class (left ), repr_class (right ))
458
- elif exact :
459
- msg = f"{ obj } classes are different"
460
- raise_assert_detail (obj , msg , repr_class (left ), repr_class (right ))
460
+ # accept equivalence of all NumericIndex (sub-)classes
461
+ if isinstance (left , NumericIndex ) and isinstance (right , NumericIndex ):
462
+ return
463
+
464
+ msg = f"{ obj } classes are different"
465
+ raise_assert_detail (obj , msg , repr_class (left ), repr_class (right ))
461
466
462
467
463
468
def assert_attr_equal (attr : str , left , right , obj : str = "Attributes" ):
0 commit comments