@@ -29,19 +29,19 @@ def method(self, request):
29
29
"""
30
30
return request .param
31
31
32
- def test_rank (self ):
32
+ def test_rank (self , float_frame ):
33
33
rankdata = pytest .importorskip ('scipy.stats.rankdata' )
34
34
35
- self . frame ['A' ][::2 ] = np .nan
36
- self . frame ['B' ][::3 ] = np .nan
37
- self . frame ['C' ][::4 ] = np .nan
38
- self . frame ['D' ][::5 ] = np .nan
35
+ float_frame ['A' ][::2 ] = np .nan
36
+ float_frame ['B' ][::3 ] = np .nan
37
+ float_frame ['C' ][::4 ] = np .nan
38
+ float_frame ['D' ][::5 ] = np .nan
39
39
40
- ranks0 = self . frame .rank ()
41
- ranks1 = self . frame .rank (1 )
42
- mask = np .isnan (self . frame .values )
40
+ ranks0 = float_frame .rank ()
41
+ ranks1 = float_frame .rank (1 )
42
+ mask = np .isnan (float_frame .values )
43
43
44
- fvals = self . frame .fillna (np .inf ).values
44
+ fvals = float_frame .fillna (np .inf ).values
45
45
46
46
exp0 = np .apply_along_axis (rankdata , 0 , fvals )
47
47
exp0 [mask ] = np .nan
@@ -109,32 +109,32 @@ def test_rank2(self):
109
109
result = df .rank (1 , numeric_only = False , ascending = False )
110
110
tm .assert_frame_equal (result , expected )
111
111
112
- # mixed-type frames
113
- self .mixed_frame ['datetime' ] = datetime .now ()
114
- self .mixed_frame ['timedelta' ] = timedelta (days = 1 , seconds = 1 )
115
-
116
- result = self .mixed_frame .rank (1 )
117
- expected = self .mixed_frame .rank (1 , numeric_only = True )
118
- tm .assert_frame_equal (result , expected )
119
-
120
112
df = DataFrame ({"a" : [1e-20 , - 5 , 1e-20 + 1e-40 , 10 ,
121
113
1e60 , 1e80 , 1e-30 ]})
122
114
exp = DataFrame ({"a" : [3.5 , 1. , 3.5 , 5. , 6. , 7. , 2. ]})
123
115
tm .assert_frame_equal (df .rank (), exp )
124
116
125
- def test_rank_na_option (self ):
117
+ def test_rank_mixed_frame (self , float_string_frame ):
118
+ float_string_frame ['datetime' ] = datetime .now ()
119
+ float_string_frame ['timedelta' ] = timedelta (days = 1 , seconds = 1 )
120
+
121
+ result = float_string_frame .rank (1 )
122
+ expected = float_string_frame .rank (1 , numeric_only = True )
123
+ tm .assert_frame_equal (result , expected )
124
+
125
+ def test_rank_na_option (self , float_frame ):
126
126
rankdata = pytest .importorskip ('scipy.stats.rankdata' )
127
127
128
- self . frame ['A' ][::2 ] = np .nan
129
- self . frame ['B' ][::3 ] = np .nan
130
- self . frame ['C' ][::4 ] = np .nan
131
- self . frame ['D' ][::5 ] = np .nan
128
+ float_frame ['A' ][::2 ] = np .nan
129
+ float_frame ['B' ][::3 ] = np .nan
130
+ float_frame ['C' ][::4 ] = np .nan
131
+ float_frame ['D' ][::5 ] = np .nan
132
132
133
133
# bottom
134
- ranks0 = self . frame .rank (na_option = 'bottom' )
135
- ranks1 = self . frame .rank (1 , na_option = 'bottom' )
134
+ ranks0 = float_frame .rank (na_option = 'bottom' )
135
+ ranks1 = float_frame .rank (1 , na_option = 'bottom' )
136
136
137
- fvals = self . frame .fillna (np .inf ).values
137
+ fvals = float_frame .fillna (np .inf ).values
138
138
139
139
exp0 = np .apply_along_axis (rankdata , 0 , fvals )
140
140
exp1 = np .apply_along_axis (rankdata , 1 , fvals )
@@ -143,11 +143,11 @@ def test_rank_na_option(self):
143
143
tm .assert_almost_equal (ranks1 .values , exp1 )
144
144
145
145
# top
146
- ranks0 = self . frame .rank (na_option = 'top' )
147
- ranks1 = self . frame .rank (1 , na_option = 'top' )
146
+ ranks0 = float_frame .rank (na_option = 'top' )
147
+ ranks1 = float_frame .rank (1 , na_option = 'top' )
148
148
149
- fval0 = self . frame . fillna ((self . frame .min () - 1 ).to_dict ()).values
150
- fval1 = self . frame .T
149
+ fval0 = float_frame . fillna ((float_frame .min () - 1 ).to_dict ()).values
150
+ fval1 = float_frame .T
151
151
fval1 = fval1 .fillna ((fval1 .min () - 1 ).to_dict ()).T
152
152
fval1 = fval1 .fillna (np .inf ).values
153
153
@@ -160,10 +160,10 @@ def test_rank_na_option(self):
160
160
# descending
161
161
162
162
# bottom
163
- ranks0 = self . frame .rank (na_option = 'top' , ascending = False )
164
- ranks1 = self . frame .rank (1 , na_option = 'top' , ascending = False )
163
+ ranks0 = float_frame .rank (na_option = 'top' , ascending = False )
164
+ ranks1 = float_frame .rank (1 , na_option = 'top' , ascending = False )
165
165
166
- fvals = self . frame .fillna (np .inf ).values
166
+ fvals = float_frame .fillna (np .inf ).values
167
167
168
168
exp0 = np .apply_along_axis (rankdata , 0 , - fvals )
169
169
exp1 = np .apply_along_axis (rankdata , 1 , - fvals )
@@ -174,11 +174,11 @@ def test_rank_na_option(self):
174
174
# descending
175
175
176
176
# top
177
- ranks0 = self . frame .rank (na_option = 'bottom' , ascending = False )
178
- ranks1 = self . frame .rank (1 , na_option = 'bottom' , ascending = False )
177
+ ranks0 = float_frame .rank (na_option = 'bottom' , ascending = False )
178
+ ranks1 = float_frame .rank (1 , na_option = 'bottom' , ascending = False )
179
179
180
- fval0 = self . frame . fillna ((self . frame .min () - 1 ).to_dict ()).values
181
- fval1 = self . frame .T
180
+ fval0 = float_frame . fillna ((float_frame .min () - 1 ).to_dict ()).values
181
+ fval1 = float_frame .T
182
182
fval1 = fval1 .fillna ((fval1 .min () - 1 ).to_dict ()).T
183
183
fval1 = fval1 .fillna (np .inf ).values
184
184
@@ -192,11 +192,11 @@ def test_rank_na_option(self):
192
192
msg = "na_option must be one of 'keep', 'top', or 'bottom'"
193
193
194
194
with pytest .raises (ValueError , match = msg ):
195
- self . frame .rank (na_option = 'bad' , ascending = False )
195
+ float_frame .rank (na_option = 'bad' , ascending = False )
196
196
197
197
# invalid type
198
198
with pytest .raises (ValueError , match = msg ):
199
- self . frame .rank (na_option = True , ascending = False )
199
+ float_frame .rank (na_option = True , ascending = False )
200
200
201
201
def test_rank_axis (self ):
202
202
# check if using axes' names gives the same result
0 commit comments