@@ -314,16 +314,18 @@ 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 )
318
- assert_attr_equal ("dtype" , left , right , obj = obj )
319
317
320
318
# Skip exact dtype checking when `check_categorical` is False
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 )
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 )
327
329
328
330
def _get_ilevel_values (index , level ):
329
331
# accept level number only
0 commit comments