@@ -1965,6 +1965,55 @@ def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
1965
1965
exp_df = DataFrame (exp * len (grps ), columns = ['val' ])
1966
1966
assert_frame_equal (result , exp_df )
1967
1967
1968
+ @pytest .mark .parametrize ("grps" , [
1969
+ ['qux' ], ['qux' , 'quux' ]])
1970
+ @pytest .mark .parametrize ("vals" , [
1971
+ [- np .inf , - np .inf , np .nan , 1. , np .nan , np .inf , np .inf ],
1972
+ ])
1973
+ @pytest .mark .parametrize ("ties_method,ascending,na_option,exp" , [
1974
+ ('average' , True , 'keep' , [1.5 , 1.5 , np .nan , 3 , np .nan , 4.5 , 4.5 ]),
1975
+ ('average' , True , 'top' , [3.5 , 3.5 , 1.5 , 5. , 1.5 , 6.5 , 6.5 ]),
1976
+ ('average' , True , 'bottom' , [1.5 , 1.5 , 6.5 , 3. , 6.5 , 4.5 , 4.5 ]),
1977
+ ('average' , False , 'keep' , [4.5 , 4.5 , np .nan , 3 , np .nan , 1.5 , 1.5 ]),
1978
+ ('average' , False , 'top' , [6.5 , 6.5 , 1.5 , 5. , 1.5 , 3.5 , 3.5 ]),
1979
+ ('average' , False , 'bottom' , [4.5 , 4.5 , 6.5 , 3. , 6.5 , 1.5 , 1.5 ]),
1980
+ ('min' , True , 'keep' , [1. , 1. , np .nan , 3. , np .nan , 4. , 4. ]),
1981
+ ('min' , True , 'top' , [3. , 3. , 1. , 5. , 1. , 6. , 6. ]),
1982
+ ('min' , True , 'bottom' , [1. , 1. , 6. , 3. , 6. , 4. , 4. ]),
1983
+ ('min' , False , 'keep' , [4. , 4. , np .nan , 3. , np .nan , 1. , 1. ]),
1984
+ ('min' , False , 'top' , [6. , 6. , 1. , 5. , 1. , 3. , 3. ]),
1985
+ ('min' , False , 'bottom' , [4. , 4. , 6. , 3. , 6. , 1. , 1. ]),
1986
+ ('max' , True , 'keep' , [2. , 2. , np .nan , 3. , np .nan , 5. , 5. ]),
1987
+ ('max' , True , 'top' , [4. , 4. , 2. , 5. , 2. , 7. , 7. ]),
1988
+ ('max' , True , 'bottom' , [2. , 2. , 7. , 3. , 7. , 5. , 5. ]),
1989
+ ('max' , False , 'keep' , [5. , 5. , np .nan , 3. , np .nan , 2. , 2. ]),
1990
+ ('max' , False , 'top' , [7. , 7. , 2. , 5. , 2. , 4. , 4. ]),
1991
+ ('max' , False , 'bottom' , [5. , 5. , 7. , 3. , 7. , 2. , 2. ]),
1992
+ ('first' , True , 'keep' , [1. , 2. , np .nan , 3. , np .nan , 4. , 5. ]),
1993
+ ('first' , True , 'top' , [3. , 4. , 1. , 5. , 2. , 6. , 7. ]),
1994
+ ('first' , True , 'bottom' , [1. , 2. , 6. , 3. , 7. , 4. , 5. ]),
1995
+ ('first' , False , 'keep' , [4. , 5. , np .nan , 3. , np .nan , 1. , 2. ]),
1996
+ ('first' , False , 'top' , [6. , 7. , 1. , 5. , 2. , 3. , 4. ]),
1997
+ ('first' , False , 'bottom' , [4. , 5. , 6. , 3. , 7. , 1. , 2. ]),
1998
+ ('dense' , True , 'keep' , [1. , 1. , np .nan , 2. , np .nan , 3. , 3. ]),
1999
+ ('dense' , True , 'top' , [2. , 2. , 1. , 3. , 1. , 4. , 4. ]),
2000
+ ('dense' , True , 'bottom' , [1. , 1. , 4. , 2. , 4. , 3. , 3. ]),
2001
+ ('dense' , False , 'keep' , [3. , 3. , np .nan , 2. , np .nan , 1. , 1. ]),
2002
+ ('dense' , False , 'top' , [4. , 4. , 1. , 3. , 1. , 2. , 2. ]),
2003
+ ('dense' , False , 'bottom' , [3. , 3. , 4. , 2. , 4. , 1. , 1. ])
2004
+ ])
2005
+ def test_infs_n_nans (self , grps , vals , ties_method , ascending , na_option ,
2006
+ exp ):
2007
+ # GH 20561
2008
+ key = np .repeat (grps , len (vals ))
2009
+ vals = vals * len (grps )
2010
+ df = DataFrame ({'key' : key , 'val' : vals })
2011
+ result = df .groupby ('key' ).rank (method = ties_method ,
2012
+ ascending = ascending ,
2013
+ na_option = na_option )
2014
+ exp_df = DataFrame (exp * len (grps ), columns = ['val' ])
2015
+ assert_frame_equal (result , exp_df )
2016
+
1968
2017
@pytest .mark .parametrize ("grps" , [
1969
2018
['qux' ], ['qux' , 'quux' ]])
1970
2019
@pytest .mark .parametrize ("vals" , [
0 commit comments