8000 TST/CLN: Fixturize frame/test_analytics by h-vetinari · Pull Request #22733 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

TST/CLN: Fixturize frame/test_analytics #22733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Consistent naming of parameters"
This reverts commit b043bb4.
  • Loading branch information
h-vetinari committed Oct 5, 2018
commit 48272d9398f0b547d77c9e9774c102604ce3156b
62 changes: 31 additions & 31 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
import pandas.util._test_decorators as td


def _check_stat_op(opname, alternative, main_frame, float_frame,
def _check_stat_op(name, alternative, main_frame, float_frame,
float_string_frame, has_skipna=True,
has_numeric_only=False, check_dtype=True,
check_dates=False, check_less_precise=False,
skipna_alternative=None):

f = getattr(main_frame, opname)
f = getattr(main_frame, name)

if check_dates:
df = DataFrame({'b': date_range('1/1/2001', periods=2)})
_f = getattr(df, opname)
_f = getattr(df, name)
result = _f()
assert isinstance(result, Series)

df['a'] = lrange(len(df))
result = getattr(df, opname)()
result = getattr(df, name)()
assert isinstance(result, Series)
assert len(result)

Expand All @@ -67,7 +67,7 @@ def wrapper(x):
tm.assert_series_equal(result0, main_frame.apply(skipna_wrapper),
check_dtype=check_dtype,
check_less_precise=check_less_precise)
if opname in ['sum', 'prod']:
if name in ['sum', 'prod']:
expected = main_frame.apply(skipna_wrapper, axis=1)
tm.assert_series_equal(result1, expected, check_dtype=False,
check_less_precise=check_less_precise)
Expand All @@ -84,30 +84,30 @@ def wrapper(x):
# all NA case
if has_skipna:
all_na = float_frame * np.NaN
r0 = getattr(all_na, opname)(axis=0)
r1 = getattr(all_na, opname)(axis=1)
if opname in ['sum', 'prod']:
unit = int(opname == 'prod')
r0 = getattr(all_na, name)(axis=0)
r1 = getattr(all_na, name)(axis=1)
if name in ['sum', 'prod']:
unit = int(name == 'prod')
expected = pd.Series(unit, index=r0.index, dtype=r0.dtype)
tm.assert_series_equal(r0, expected)
expected = pd.Series(unit, index=r1.index, dtype=r1.dtype)
tm.assert_series_equal(r1, expected)

# make sure works on mixed-type frame
getattr(float_string_frame, opname)(axis=0)
getattr(float_string_frame, opname)(axis=1)
getattr(float_string_frame, name)(axis=0)
getattr(float_string_frame, name)(axis=1)

if has_numeric_only:
getattr(float_string_frame, opname)(axis=0, numeric_only=True)
getattr(float_string_frame, opname)(axis=1, numeric_only=True)
getattr(float_frame, opname)(axis=0, numeric_only=False)
getattr(float_frame, opname)(axis=1, numeric_only=False)
getattr(float_string_frame, name)(axis=0, numeric_only=True)
getattr(float_string_frame, name)(axis=1, numeric_only=True)
getattr(float_frame, name)(axis=0, numeric_only=False)
getattr(float_frame, name)(axis=1, numeric_only=False)


def _check_bool_op(opname, alternative, main_frame, float_string_frame,
def _check_bool_op(name, alternative, frame, float_string_frame,
has_skipna=True, has_bool_only=False):

f = getattr(main_frame, opname)
f = getattr(frame, name)

if has_skipna:
< EEC8 span class='blob-code-inner blob-code-marker ' data-code-marker=" "> def skipna_wrapper(x):
Expand All @@ -119,28 +119,28 @@ def wrapper(x):

result0 = f(axis=0, skipna=False)
result1 = f(axis=1, skipna=False)
tm.assert_series_equal(result0, main_frame.apply(wrapper))
tm.assert_series_equal(result1, main_frame.apply(wrapper, axis=1),
tm.assert_series_equal(result0, frame.apply(wrapper))
tm.assert_series_equal(result1, frame.apply(wrapper, axis=1),
check_dtype=False) # HACK: win32
else:
skipna_wrapper = alternative
wrapper = alternative

result0 = f(axis=0)
result1 = f(axis=1)
tm.assert_series_equal(result0, main_frame.apply(skipna_wrapper))
tm.assert_series_equal(result1, main_frame.apply(skipna_wrapper, axis=1),
tm.assert_series_equal(result0, frame.apply(skipna_wrapper))
tm.assert_series_equal(result1, frame.apply(skipna_wrapper, axis=1),
check_dtype=False)

# bad axis
pytest.raises(ValueError, f, axis=2)

# all NA case
if has_skipna:
all_na = main_frame * np.NaN
r0 = getattr(all_na, opname)(axis=0)
r1 = getattr(all_na, opname)(axis=1)
if opname == 'any':
all_na = frame * np.NaN
r0 = getattr(all_na, name)(axis=0)
r1 = getattr(all_na, name)(axis=1)
if name == 'any':
assert not r0.any()
assert not r1.any()
else:
Expand All @@ -150,8 +150,8 @@ def wrapper(x):
# make sure works on mixed-type frame
mixed = float_string_frame
mixed['_bool_'] = np.random.randn(len(mixed)) > 0
getattr(mixed, opname)(axis=0)
getattr(mixed, opname)(axis=1)
getattr(mixed, name)(axis=0)
getattr(mixed, name)(axis=1)

class NonzeroFail(object):

Expand All @@ -161,10 +161,10 @@ def __nonzero__(self):
mixed['_nonzero_fail_'] = NonzeroFail()

if has_bool_only:
getattr(mixed, opname)(axis=0, bool_only=True)
getattr(mixed, opname)(axis=1, bool_only=True)
getattr(main_frame, opname)(axis=0, bool_only=False)
getattr(main_frame, opname)(axis=1, bool_only=False)
getattr(mixed, name)(axis=0, bool_only=True)
getattr(mixed, name)(axis=1, bool_only=True)
getattr(frame, name)(axis=0, bool_only=False)
getattr(frame, name)(axis=1, bool_only=False)


class TestDataFrameAnalytics():
Expand Down
0