@@ -530,7 +530,7 @@ def test_intersection_difference_match_empty(self, index, sort):
530
530
@pytest .mark .parametrize (
531
531
"method" , ["intersection" , "union" , "difference" , "symmetric_difference" ]
532
532
)
533
- def test_setop_with_categorical (index_flat , sort , method ):
533
+ def test_setop_with_categorical (index_flat , sort , method , using_infer_string ):
534
534
# MultiIndex tested separately in tests.indexes.multi.test_setops
535
535
index = index_flat
536
536
@@ -539,13 +539,21 @@ def test_setop_with_categorical(index_flat, sort, method):
539
539
540
540
result = getattr (index , method )(other , sort = sort )
541
541
expected = getattr (index , method )(index , sort = sort )
542
- if index .empty and method in ("union" , "symmetric_difference" ):
542
+ if (
543
+ using_infer_string
544
+ and index .empty
545
+ and method in ("union" , "symmetric_difference" )
546
+ ):
543
547
expected = expected .astype ("category" )
544
548
tm .assert_index_equal (result , expected , exact = exact )
545
549
546
550
result = getattr (index , method )(other [:5 ], sort = sort )
547
551
expected = getattr (index , method )(index [:5 ], sort = sort )
548
- if index .empty and method in ("union" , "symmetric_difference" ):
552
+ if (
553
+ using_infer_string
554
+ and index .empty
555
+ and method in ("union" , "symmetric_difference" )
556
+ ):
549
557
expected = expected .astype ("category" )
550
558
tm .assert_index_equal (result , expected , exact = exact )
551
559
0 commit comments