25
25
import pandas .util ._test_decorators as td
26
26
27
27
28
- def _check_stat_op (name , alternative , main_frame , float_frame ,
28
+ def _check_stat_op (opname , alternative , main_frame , float_frame ,
29
29
float_string_frame , has_skipna = True ,
30
30
has_numeric_only = False , check_dtype = True ,
31
31
check_dates = False , check_less_precise = False ,
32
32
skipna_alternative = None ):
33
33
34
- f = getattr (main_frame , name )
34
+ f = getattr (main_frame , opname )
35
35
36
36
if check_dates :
37
37
df = DataFrame ({'b' : date_range ('1/1/2001' , periods = 2 )})
38
- _f = getattr (df , name )
38
+ _f = getattr (df , opname )
39
39
result = _f ()
40
40
assert isinstance (result , Series )
41
41
42
42
df ['a' ] = lrange (len (df ))
43
- result = getattr (df , name )()
43
+ result = getattr (df , opname )()
44
44
assert isinstance (result , Series )
45
45
assert len (result )
46
46
@@ -67,7 +67,7 @@ def wrapper(x):
67
67
tm .assert_series_equal (result0 , main_frame .apply (skipna_wrapper ),
68
68
check_dtype = check_dtype ,
69
69
check_less_precise = check_less_precise )
70
- if name in ['sum' , 'prod' ]:
70
+ if opname in ['sum' , 'prod' ]:
71
71
expected = main_frame .apply (skipna_wrapper , axis = 1 )
72
72
tm .assert_series_equal (result1 , expected , check_dtype = False ,
73
73
check_less_precise = check_less_precise )
@@ -84,30 +84,30 @@ def wrapper(x):
84
84
# all NA case
85
85
if has_skipna :
86
86
all_na = float_frame * np .NaN
87
- r0 = getattr (all_na , name )(axis = 0 )
88
- r1 = getattr (all_na , name )(axis = 1 )
89
- if name in ['sum' , 'prod' ]:
90
- unit = int (name == 'prod' )
87
+ r0 = getattr (all_na , opname )(axis = 0 )
88
+ r1 = getattr (all_na , opname )(axis = 1 )
89
+ if opname in ['sum' , 'prod' ]:
90
+ unit = int (opname == 'prod' )
91
91
expected = pd .Series (unit , index = r0 .index , dtype = r0 .dtype )
92
92
tm .assert_series_equal (r0 , expected )
93
93
expected = pd .Series (unit , index = r1 .index , dtype = r1 .dtype )
94
94
tm .assert_series_equal (r1 , expected )
95
95
96
96
# make sure works on mixed-type frame
97
- getattr (float_string_frame , name )(axis = 0 )
98
- getattr (float_string_frame , name )(axis = 1 )
97
+ getattr (float_string_frame , opname )(axis = 0 )
98
+ getattr (float_string_frame , opname )(axis = 1 )
99
99
100
100
if has_numeric_only :
101
- getattr (float_string_frame , name )(axis = 0 , numeric_only = True )
102
- getattr (float_string_frame , name )(axis = 1 , numeric_only = True )
103
- getattr (float_frame , name )(axis = 0 , numeric_only = False )
104
- getattr (float_frame , name )(axis = 1 , numeric_only = False )
101
+ getattr (float_string_frame , opname )(axis = 0 , numeric_only = True )
102
+ getattr (float_string_frame , opname )(axis = 1 , numeric_only = True )
103
+ getattr (float_frame , opname )(axis = 0 , numeric_only = False )
104
+ getattr (float_frame , opname )(axis = 1 , numeric_only = False )
105
105
106
106
107
- def _check_bool_op (name , alternative , frame , float_string_frame ,
107
+ def _check_bool_op (opname , alternative , main_frame , float_string_frame ,
108
108
has_skipna = True , has_bool_only = False ):
109
109
110
- f = getattr (frame , name )
110
+ f = getattr (main_frame , opname )
111
111
112
112
if has_skipna :
113
113
def skipna_wrapper (x ):
@@ -119,28 +119,28 @@ def wrapper(x):
119
119
120
120
result0 = f (axis = 0 , skipna = False )
121
121
result1 = f (axis = 1 , skipna = False )
122
- tm .assert_series_equal (result0 , frame .apply (wrapper ))
123
- tm .assert_series_equal (result1 , frame .apply (wrapper , axis = 1 ),
122
+ tm .assert_series_equal (result0 , main_frame .apply (wrapper ))
123
+ tm .assert_series_equal (result1 , main_frame .apply (wrapper , axis = 1 ),
124
124
check_dtype = False ) # HACK: win32
125
125
else :
126
126
skipna_wrapper = alternative
127
127
wrapper = alternative
128
128
129
129
result0 = f (axis = 0 )
130
130
result1 = f (axis = 1 )
131
- tm .assert_series_equal (result0 , frame .apply (skipna_wrapper ))
132
- tm .assert_series_equal (result1 , frame .apply (skipna_wrapper , axis = 1 ),
131
+ tm .assert_series_equal (result0 , main_frame .apply (skipna_wrapper ))
132
+ tm .assert_series_equal (result1 , main_frame .apply (skipna_wrapper , axis = 1 ),
133
133
check_dtype = False )
134
134
135
135
# bad axis
136
136
pytest .raises (ValueError , f , axis = 2 )
137
137
138
138
# all NA case
139
139
if has_skipna :
140
- all_na = frame * np .NaN
141
- r0 = getattr (all_na , name )(axis = 0 )
142
- r1 = getattr (all_na , name )(axis = 1 )
143
- if name == 'any' :
140
+ all_na = main_frame * np .NaN
141
+ r0 = getattr (all_na , opname )(axis = 0 )
142
+ r1 = getattr (all_na , opname )(axis = 1 )
143
+ if opname == 'any' :
144
144
assert not r0 .any ()
145
145
assert not r1 .any ()
146
146
else :
@@ -150,8 +150,8 @@ def wrapper(x):
150
150
# make sure works on mixed-type frame
151
151
mixed = float_string_frame
152
152
mixed ['_bool_' ] = np .random .randn (len (mixed )) > 0
153
- getattr (mixed , name )(axis = 0 )
154
- getattr (mixed , name )(axis = 1 )
153
+ getattr (mixed , opname )(axis = 0 )
154
+ getattr (mixed , opname )(axis = 1 )
155
155
156
156
class NonzeroFail (object ):
157
157
@@ -161,10 +161,10 @@ def __nonzero__(self):
161
161
mixed ['_nonzero_fail_' ] = NonzeroFail ()
162
162
163
163
if has_bool_only :
164
- getattr (mixed , name )(axis = 0 , bool_only = True )
165
- getattr (mixed , name )(axis = 1 , bool_only = True )
166
- getattr (frame , name )(axis = 0 , bool_only = False )
167
- getattr (frame , name )(axis = 1 , bool_only = False )
164
+ getattr (mixed , opname )(axis = 0 , bool_only = True )
165
+ getattr (mixed , opname )(axis = 1 , bool_only = True )
166
+ getattr (main_frame , opname )(axis = 0 , bool_only = False )
167
+ getattr (main_frame , opname )(axis = 1 , bool_only = False )
168
168
169
169
170
170
class TestDataFrameAnalytics ():
0 commit comments