@@ -197,41 +197,45 @@ def test_rank_signature(self):
197
197
s .rank (method = 'average' )
198
198
pytest .raises (ValueError , s .rank , 'average' )
199
199
200
- def test_rank_inf (self ):
201
- # test ranking -/+ inf together with randomly inserted na values
202
- mock_contents = (
203
- [- np .inf , - 50 , - 1 , - 1e-20 , - 1e-25 , - 1e-50 , 0 , 1e-40 , 1e-20 , 1e-10 ,
204
- 2 , 40 , np .inf ],
205
- [- np .inf , - 50 , - 1 , - 1e-20 , - 1e-25 , - 1e-45 , 0 , 1e-40 , 1e-20 , 1e-10 ,
206
- 2 , 40 , np .inf ],
207
- [np .iinfo (np .uint8 ).min , 1 , 2 , 100 , np .iinfo (np .uint8 ).max ],
208
- # -inf is eqivatlent to na value for int64 dtype becasue iNaT is
209
- # the same as np.iinfo(np.int64).min. The expected rank for iNaT is
210
- # nan if keep_na is true. Pending GH issue #16674
211
- [np .iinfo (np .int64 ).min + 1 , - 100 , 0 , 1 , 9999 , 100000 ,
212
- 1e10 , np .iinfo (np .int64 ).max ],
213
- [NegInfinity (), '1' , 'A' , 'BA' , 'Ba' , 'C' , Infinity ()]
214
- )
215
- dtypes = ('float64' , 'float32' , 'uint8' , 'int64' , 'object' )
200
+ @pytest .mark .parametrize ('contents,dtype' , [
201
+ ([- np .inf , - 50 , - 1 , - 1e-20 , - 1e-25 , - 1e-50 , 0 , 1e-40 , 1e-20 , 1e-10 ,
202
+ 2 , 40 , np .inf ],
203
+ 'float64' ),
204
+ ([- np .inf , - 50 , - 1 , - 1e-20 , - 1e-25 , - 1e-45 , 0 , 1e-40 , 1e-20 , 1e-10 ,
205
+ 2 , 40 , np .inf ],
206
+ 'float32' ),
207
+ ([np .iinfo (np .uint8 ).min , 1 , 2 , 100 , np .iinfo (np .uint8 ).max ],
208
+ 'uint8' ),
209
+ pytest .param ([np .iinfo (np .int64 ).min , - 100 , 0 , 1 , 9999 , 100000 ,
210
+ 1e10 , np .iinfo (np .int64 ).max ],
211
+ 'int64' ,
212
+ marks = pytest .mark .xfail (reason = '''iNaT is equivalent to
213
+ minimum value of dtype
214
+ int64 pending issue
215
+ #16674''' ),
216
+ ),
217
+ ([NegInfinity (), '1' , 'A' , 'BA' , 'Ba' , 'C' , Infinity ()],
218
+ 'object' )
219
+ ])
220
+ def test_rank_inf (self , contents , dtype ):
216
221
dtype_na_map = {
217
222
'float64' : np .nan ,
218
223
'float32' : np .nan ,
219
224
'int64' : iNaT ,
220
225
'object' : None
221
226
}
222
- for content , dtype in zip (mock_contents , dtypes ):
223
- values = np .array (content , dtype = dtype )
224
- nan_indices = np .random .choice (range (len (values )), 3 )
225
- exp_order = np .array (range (len (values )), dtype = 'float64' ) + 1.0
226
- if dtype in dtype_na_map :
227
- na_value = dtype_na_map [dtype ]
228
- values = np .insert (values , nan_indices , na_value )
229
- exp_order = np .insert (exp_order , nan_indices , np .nan )
230
- random_order = np .random .permutation (len (values ))
231
- iseries = Series (values [random_order ])
232
- exp = Series (exp_order [random_order ], dtype = 'float64' )
233
- iranks = iseries .rank ()
234
- assert_series_equal (iranks , exp )
227
+ values = np .array (contents , dtype = dtype )
228
+ nan_indices = np .random .choice (range (len (values )), 3 )
229
+ exp_order = np .array (range (len (values )), dtype = 'float64' ) + 1.0
230
+ if dtype in dtype_na_map :
231
+ na_value = dtype_na_map [dtype ]
232
+ values = np .insert (values , nan_indices , na_value )
233
+ exp_order = np .insert (exp_order , nan_indices , np .nan )
234
+ random_order = np .random .permutation (len (values ))
235
+ iseries = Series (values [random_order ])
236
+ exp = Series (exp_order [random_order ], dtype = 'float64' )
237
+ iranks = iseries .rank ()
238
+ assert_series_equal (iranks , exp )
235
239
236
240
def test_rank_tie_methods (self ):
237
241
s = self .s
0 commit comments