@@ -530,7 +530,7 @@ def test_intersection_difference_match_empty(self, index, sort):
530530@pytest .mark .parametrize (
531531 "method" , ["intersection" , "union" , "difference" , "symmetric_difference" ]
532532)
533- def test_setop_with_categorical (index_flat , sort , method ):
533+ def test_setop_with_categorical (index_flat , sort , method , using_infer_string ):
534534 # MultiIndex tested separately in tests.indexes.multi.test_setops
535535 index = index_flat
536536
@@ -539,13 +539,21 @@ def test_setop_with_categorical(index_flat, sort, method):
539539
540540 result = getattr (index , method )(other , sort = sort )
541541 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+ ):
543547 expected = expected .astype ("category" )
544548 tm .assert_index_equal (result , expected , exact = exact )
545549
546550 result = getattr (index , method )(other [:5 ], sort = sort )
547551 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+ ):
549557 expected = expected .astype ("category" )
550558 tm .assert_index_equal (result , expected , exact = exact )
551559
0 commit comments