@@ -200,14 +200,37 @@ def test_corr_rank_ordered_categorical(self, method,):
200200 ser_ord_float = pd .Series ([2.0 , 3.0 , 4.5 , 6.5 ])
201201
202202 corr_calc = ser_ord_cat .corr (ser_ord_int , method = method )
203- corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_int )[0 ]
203+ corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_int , nan_policy = "omit" )[0 ]
204204 tm .assert_almost_equal (corr_calc , corr_expected )
205205
206206 corr_calc = ser_ord_cat .corr (ser_ord_float , method = method )
207- corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_float )[0 ]
207+ corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_float , nan_policy = "omit" )[0 ]
208208 tm .assert_almost_equal (corr_calc , corr_expected )
209209
210210 corr_calc = ser_ord_cat .corr (ser_ord_cat , method = method )
211- corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_cat_codes )[0 ]
211+ corr_expected = method_scipy_func [method ](ser_ord_cat_codes , ser_ord_cat_codes , nan_policy = "omit" )[0 ]
212212 tm .assert_almost_equal (corr_calc , corr_expected )
213+
214+ ser_ord_cat_shuff = pd .Series ( pd .Categorical (
215+ ["h" , "low" , "vh" , "m" ],
216+ categories = ["low" , "m" , "h" , "vh" ], ordered = True
217+ ))
218+ ser_ord_cat_shuff_codes = ser_ord_cat_shuff .cat .codes .replace (- 1 , np .nan )
213219
220+ corr_calc = ser_ord_cat_shuff .corr (ser_ord_cat , method = method )
221+ corr_expected = method_scipy_func [method ](ser_ord_cat_shuff_codes , ser_ord_cat_codes , nan_policy = "omit" )[0 ]
222+ tm .assert_almost_equal (corr_calc , corr_expected )
223+
224+ corr_calc = ser_ord_cat_shuff .corr (ser_ord_cat_shuff , method = method )
225+ corr_expected = method_scipy_func [method ](ser_ord_cat_shuff_codes , ser_ord_cat_shuff_codes , nan_policy = "omit" )[0 ]
226+ tm .assert_almost_equal (corr_calc , corr_expected )
227+
228+ ser_ord_cat_with_nan = pd .Series ( pd .Categorical (
229+ ["h" , "low" , "vh" , None , "m" ],
230+ categories = ["low" , "m" , "h" , "vh" ], ordered = True
231+ ))
232+ ser_ord_cat_shuff_with_nan_codes = ser_ord_cat_with_nan .cat .codes .replace (- 1 , np .nan )
233+ ser_ord_int = pd .Series ([2 , 0 , 1 , 3 , None ])
234+ corr_calc = ser_ord_cat_with_nan .corr (ser_ord_int , method = method )
235+ corr_expected = method_scipy_func [method ](ser_ord_cat_shuff_with_nan_codes , ser_ord_int , nan_policy = "omit" )[0 ]
236+ tm .assert_almost_equal (corr_calc , corr_expected )
0 commit comments