@@ -1898,7 +1898,7 @@ def test_rank_apply(self):
1898
1898
@pytest .mark .parametrize ("grps" , [
1899
1899
['qux' ], ['qux' , 'quux' ]])
1900
1900
@pytest .mark .parametrize ("vals" , [
1901
- [2 , 2 , 8 , 2 , 6 ], [ 'bar' , 'bar' , 'foo' , 'bar' , 'baz' ],
1901
+ [2 , 2 , 8 , 2 , 6 ],
1902
1902
[pd .Timestamp ('2018-01-02' ), pd .Timestamp ('2018-01-02' ),
1903
1903
pd .Timestamp ('2018-01-08' ), pd .Timestamp ('2018-01-02' ),
1904
1904
pd .Timestamp ('2018-01-06' )]])
@@ -1925,8 +1925,6 @@ def test_rank_apply(self):
1925
1925
('dense' , False , True , [.6 , .6 , .2 , .6 , .4 ]),
1926
1926
])
1927
1927
def test_rank_args (self , grps , vals , ties_method , ascending , pct , exp ):
1928
- if ties_method == 'first' and vals [0 ] == 'bar' :
1929
- pytest .xfail ("See GH 19482" )
1930
1928
key = np .repeat (grps , len (vals ))
1931
1929
vals = vals * len (grps )
1932
1930
df = DataFrame ({'key' : key , 'val' : vals })
@@ -1940,7 +1938,6 @@ def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
1940
1938
['qux' ], ['qux' , 'quux' ]])
1941
1939
@pytest .mark .parametrize ("vals" , [
1942
1940
[2 , 2 , np .nan , 8 , 2 , 6 , np .nan , np .nan ], # floats
1943
- ['bar' , 'bar' , np .nan , 'foo' , 'bar' , 'baz' , np .nan , np .nan ], # objects
1944
1941
[pd .Timestamp ('2018-01-02' ), pd .Timestamp ('2018-01-02' ), np .nan ,
1945
1942
pd .Timestamp ('2018-01-08' ), pd .Timestamp ('2018-01-02' ),
1946
1943
pd .Timestamp ('2018-01-06' ), np .nan , np .nan ]
@@ -2019,8 +2016,6 @@ def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
2019
2016
])
2020
2017
def test_rank_args_missing (self , grps , vals , ties_method , ascending ,
2021
2018
na_option , pct , exp ):
2022
- if ties_method == 'first' and vals [0 ] == 'bar' :
2023
- pytest .xfail ("See GH 19482" )
2024
2019
key = np .repeat (grps , len (vals ))
2025
2020
vals = vals * len (grps )
2026
2021
df = DataFrame ({'key' : key , 'val' : vals })
@@ -2031,6 +2026,24 @@ def test_rank_args_missing(self, grps, vals, ties_method, ascending,
2031
2026
exp_df = DataFrame (exp * len (grps ), columns = ['val' ])
2032
2027
assert_frame_equal (result , exp_df )
2033
2028
2029
+ @pytest .mark .parametrize ("ties_method" , [
2030
+ 'average' , 'min' , 'max' , 'first' , 'dense' ])
2031
+ @pytest .mark .parametrize ("ascending" , [True , False ])
2032
+ @pytest .mark .parametrize ("na_option" , ["keep" , "top" , "bottom" ])
2033
+ @pytest .mark .parametrize ("pct" , [True , False ])
2034
+ @pytest .mark .parametrize ("vals" , [
2035
+ ['bar' , 'bar' , 'foo' , 'bar' , 'baz' ],
2036
+ ['bar' , np .nan , 'foo' , np .nan , 'baz' ]
2037
+ ])
2038
+ def test_rank_object_raises (self , ties_method , ascending , na_option ,
2039
+ pct , vals ):
2040
+ df = DataFrame ({'key' : ['foo' ] * 5 , 'val' : vals })
2041
+ with tm .assert_raises_regex (ValueError ,
2042
+ "rank not supported for object dtypes" ):
2043
+ df .groupby ('key' ).rank (method = ties_method ,
2044
+ ascending = ascending ,
2045
+ na_option = na_option , pct = pct )
2046
+
2034
2047
def test_dont_clobber_name_column (self ):
2035
2048
df = DataFrame ({'key' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' ],
2036
2049
'name' : ['foo' , 'bar' , 'baz' ] * 2 })
0 commit comments