@@ -252,14 +252,24 @@ def test_rank_object_raises(ties_method, ascending, na_option,
252
252
with tm .assert_raises_regex (TypeError , "not callable" ):
253
253
df .groupby ('key' ).rank (method = ties_method ,
254
254
ascending = ascending ,
255
- na_option = 'bad' , pct = pct )
255
+ na_option = na_option , pct = pct )
256
256
257
- with tm .assert_raises_regex (TypeError , "not callable" ):
258
- df .groupby ('key' ).rank (method = ties_method ,
259
- ascending = ascending ,
260
- na_option = True , pct = pct )
261
257
262
- with tm .assert_raises_regex (TypeError , "not callable" ):
258
+ @pytest .mark .parametrize ("na_option" , [True , "bad" , 1 ])
259
+ @pytest .mark .parametrize ("ties_method" , [
260
+ 'average' , 'min' , 'max' , 'first' , 'dense' ])
261
+ @pytest .mark .parametrize ("ascending" , [True , False ])
262
+ @pytest .mark .parametrize ("pct" , [True , False ])
263
+ @pytest .mark .parametrize ("vals" , [
264
+ ['bar' , 'bar' , 'foo' , 'bar' , 'baz' ],
265
+ ['bar' , np .nan , 'foo' , np .nan , 'baz' ],
266
+ [1 , np .nan , 2 , np .nan , 3 ]
267
+ ])
268
+ def test_rank_naoption_raises (ties_method , ascending , na_option , pct , vals ):
269
+ df = DataFrame ({'key' : ['foo' ] * 5 , 'val' : vals })
270
+ msg = "na_option must be one of 'keep', 'top', or 'bottom'"
271
+
272
+ with tm .assert_raises_regex (TypeError , msg ):
263
273
df .groupby ('key' ).rank (method = ties_method ,
264
274
ascending = ascending ,
265
- na_option = na_option , pct = pct )
275
+ na_option = 'bad' , pct = pct )
0 commit comments