Skip to content

Commit be4605d

Browse files
committed
Clean res/exp in frame/test_apply.py
1 parent e903579 commit be4605d

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

pandas/tests/frame/test_apply.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def test_apply_empty(self, float_frame, empty_frame):
9595
assert_series_equal(result, expected)
9696

9797
# 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)
101101

102102
def test_apply_with_reduce_empty(self, empty_frame):
103103
# reduce with an empty DataFrame
@@ -126,12 +126,13 @@ def test_apply_deprecate_reduce(self, empty_frame):
126126
def test_apply_standard_nonunique(self):
127127
df = DataFrame(
128128
[[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)
132129

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)
135136

136137
@pytest.mark.parametrize('func', ['sum', 'mean', 'min', 'max', 'std'])
137138
@pytest.mark.parametrize('args,kwds', [
@@ -265,13 +266,13 @@ def _check(df, f):
265266
is_reduction = not isinstance(test_res, np.ndarray)
266267

267268
def _checkit(axis=0, raw=False):
268-
res = df.apply(f, axis=axis, raw=raw)
269+
result = df.apply(f, axis=axis, raw=raw)
269270
if is_reduction:
270271
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
273274
else:
274-
assert isinstance(res, DataFrame)
275+
assert isinstance(result, DataFrame)
275276

276277
_checkit()
277278
_checkit(axis=1)
@@ -298,16 +299,16 @@ def subtract_and_divide(x, sub, divide=1):
298299
return (x - sub) / divide
299300

300301
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)
303304

304305
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)
307308

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)
311312

312313
def test_apply_yield_list(self, float_frame):
313314
result = float_frame.apply(list)
@@ -529,12 +530,12 @@ def test_applymap_box(self):
529530
'd': [pd.Period('2011-01-01', freq='M'),
530531
pd.Period('2011-01-02', freq='M')]})
531532

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)
538539

539540
def test_frame_apply_dont_convert_datetime64(self):
540541
from pandas.tseries.offsets import BDay

0 commit comments

Comments
 (0)