@@ -149,21 +149,23 @@ def test_use_inf_as_na_outside_context(self, values, expected):
149
149
expected = DataFrame (expected )
150
150
tm .assert_frame_equal (result , expected )
151
151
152
- def test_compare_categorical_with_missing (self ):
152
+ @pytest .mark .parametrize (
153
+ "a1, a2, categories" ,
154
+ [
155
+ (["a" , "b" , "c" ], [np .nan , "a" , "b" ], ["a" , "b" , "c" ]),
156
+ ([1 , 2 , 3 ], [np .nan , 1 , 2 ], [1 , 2 , 3 ]),
157
+ ],
158
+ )
159
+ def test_compare_categorical_with_missing (self , a1 , a2 , categories ):
153
160
# GH 28384
154
- a1 = ["a" , "b" , np .nan ]
155
- a2 = ["b" , "a" , "a" ]
156
-
157
- cat_s1 = Series (a1 , dtype = "category" )
158
- cat_s2 = Series (a2 , dtype = "category" )
159
- result = cat_s1 != cat_s2
161
+ cat_type = CategoricalDtype (categories )
160
162
161
- expected = Series ([True , True , True ], dtype = "bool" )
163
+ # !=
164
+ result = Series (a1 , dtype = cat_type ) != Series (a2 , dtype = cat_type )
165
+ expected = Series (a1 ) != Series (a2 )
162
166
tm .assert_series_equal (result , expected )
163
167
164
- # categorical vs noncategorical
165
- noncat_s1 = Series (a1 )
166
- noncat_s2 = Series (a2 )
167
- expected = noncat_s1 != noncat_s2
168
-
168
+ # ==
169
+ result = Series (a1 , dtype = cat_type ) == Series (a2 , dtype = cat_type )
170
+ expected = Series (a1 ) == Series (a2 )
169
171
tm .assert_series_equal (result , expected )
0 commit comments