@@ -95,9 +95,9 @@ def test_apply_empty(self, float_frame, empty_frame):
95
95
assert_series_equal (result , expected )
96
96
97
97
# 2476
98
- xp = DataFrame (index = ['a' ])
99
- rs = xp .apply (lambda x : x ['a' ], axis = 1 )
100
- assert_frame_equal (xp , rs )
98
+ expected = DataFrame (index = ['a' ])
99
+ result = expected .apply (lambda x : x ['a' ], axis = 1 )
100
+ assert_frame_equal (expected , result )
101
101
102
102
def test_apply_with_reduce_empty (self , empty_frame ):
103
103
# reduce with an empty DataFrame
@@ -126,12 +126,13 @@ def test_apply_deprecate_reduce(self, empty_frame):
126
126
def test_apply_standard_nonunique (self ):
127
127
df = DataFrame (
128
128
[[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], index = ['a' , 'a' , 'c' ])
129
- rs = df .apply (lambda s : s [0 ], axis = 1 )
130
- xp = Series ([1 , 4 , 7 ], ['a' , 'a' , 'c' ])
131
- assert_series_equal (rs , xp )
132
129
133
- rs = df .T .apply (lambda s : s [0 ], axis = 0 )
134
- assert_series_equal (rs , xp )
130
+ result = df .apply (lambda s : s [0 ], axis = 1 )
131
+ expected = Series ([1 , 4 , 7 ], ['a' , 'a' , 'c' ])
132
+ assert_series_equal (result , expected )
133
+
134
+ result = df .T .apply (lambda s : s [0 ], axis = 0 )
135
+ assert_series_equal (result , expected )
135
136
136
137
@pytest .mark .parametrize ('func' , ['sum' , 'mean' , 'min' , 'max' , 'std' ])
137
138
@pytest .mark .parametrize ('args,kwds' , [
@@ -265,13 +266,13 @@ def _check(df, f):
265
266
is_reduction = not isinstance (test_res , np .ndarray )
266
267
267
268
def _checkit (axis = 0 , raw = False ):
268
- res = df .apply (f , axis = axis , raw = raw )
269
+ result = df .apply (f , axis = axis , raw = raw )
269
270
if is_reduction :
270
271
agg_axis = df ._get_agg_axis (axis )
271
- assert isinstance (res , Series )
272
- assert res .index is agg_axis
272
+ assert isinstance (result , Series )
273
+ assert result .index is agg_axis
273
274
else :
274
- assert isinstance (res , DataFrame )
275
+ assert isinstance (result , DataFrame )
275
276
276
277
_checkit ()
277
278
_checkit (axis = 1 )
@@ -298,16 +299,16 @@ def subtract_and_divide(x, sub, divide=1):
298
299
return (x - sub ) / divide
299
300
300
301
result = float_frame .apply (add_some , howmuch = 2 )
301
- exp = float_frame .apply (lambda x : x + 2 )
302
- assert_frame_equal (result , exp )
302
+ expected = float_frame .apply (lambda x : x + 2 )
303
+ assert_frame_equal (result , expected )
303
304
304
305
result = float_frame .apply (agg_and_add , howmuch = 2 )
305
- exp = float_frame .apply (lambda x : x .mean () + 2 )
306
- assert_series_equal (result , exp )
306
+ expected = float_frame .apply (lambda x : x .mean () + 2 )
307
+ assert_series_equal (result , expected )
307
308
308
- res = float_frame .apply (subtract_and_divide , args = (2 ,), divide = 2 )
309
- exp = float_frame .apply (lambda x : (x - 2. ) / 2. )
310
- assert_frame_equal (res , exp )
309
+ result = float_frame .apply (subtract_and_divide , args = (2 ,), divide = 2 )
310
+ expected = float_frame .apply (lambda x : (x - 2. ) / 2. )
311
+ assert_frame_equal (result , expected )
311
312
312
313
def test_apply_yield_list (self , float_frame ):
313
314
result = float_frame .apply (list )
@@ -529,12 +530,12 @@ def test_applymap_box(self):
529
530
'd' : [pd .Period ('2011-01-01' , freq = 'M' ),
530
531
pd .Period ('2011-01-02' , freq = 'M' )]})
531
532
532
- res = df .applymap (lambda x : '{0}' .format (x .__class__ .__name__ ))
533
- exp = pd .DataFrame ({'a' : ['Timestamp' , 'Timestamp' ],
534
- 'b' : ['Timestamp' , 'Timestamp' ],
535
- 'c' : ['Timedelta' , 'Timedelta' ],
536
- 'd' : ['Period' , 'Period' ]})
537
- tm .assert_frame_equal (res , exp )
533
+ result = df .applymap (lambda x : '{0}' .format (x .__class__ .__name__ ))
534
+ expected = pd .DataFrame ({'a' : ['Timestamp' , 'Timestamp' ],
535
+ 'b' : ['Timestamp' , 'Timestamp' ],
536
+ 'c' : ['Timedelta' , 'Timedelta' ],
537
+ 'd' : ['Period' , 'Period' ]})
538
+ tm .assert_frame_equal (result , expected )
538
539
539
540
def test_frame_apply_dont_convert_datetime64 (self ):
540
541
from pandas .tseries .offsets import BDay
0 commit comments