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
Make _check_stat_op and _check_bool_op run
  • Loading branch information
h-vetinari committed Sep 25, 2018
commit 6c4a7027b0bfe64f72a6ac4831f94eee15406567
106 changes: 53 additions & 53 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pandas.util._test_decorators as td


def _check_stat_op(self, name, 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,
Expand Down Expand Up @@ -103,7 +103,7 @@ def wrapper(x):
tm.assert_series_equal(r1, expected)


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

f = getattr(frame, name)
Expand Down Expand Up @@ -596,10 +596,10 @@ def test_reduce_mixed_frame(self):

def test_count(self, float_frame_with_na, float_frame, float_string_frame):
f = lambda s: notna(s).sum()
self._check_stat_op('count', f, float_frame_with_na, float_frame,
float_string_frame, has_skipna=False,
has_numeric_only=True, check_dtype=False,
check_dates=True)
_check_stat_op('count', f, float_frame_with_na, float_frame,
float_string_frame, has_skipna=False,
has_numeric_only=True, check_dtype=False,
check_dates=True)

# corner case
frame = DataFrame()
Expand Down Expand Up @@ -628,9 +628,9 @@ def test_count(self, float_frame_with_na, float_frame, float_string_frame):
def test_nunique(self, float_frame_with_na, float_frame,
float_string_frame):
f = lambda s: len(algorithms.unique1d(s.dropna()))
self._check_stat_op('nunique', f, float_frame_with_na,
float_frame, float_string_frame, has_skipna=False,
check_dtype=False, check_dates=True)
_check_stat_op('nunique', f, float_frame_with_na,
float_frame, float_string_frame, has_skipna=False,
check_dtype=False, check_dates=True)

df = DataFrame({'A': [1, 1, 1],
'B': [1, 2, 3],
Expand All @@ -644,15 +644,15 @@ def test_nunique(self, float_frame_with_na, float_frame,

def test_sum(self, float_frame_with_na, mixed_float_frame,
float_frame, float_string_frame):
self._check_stat_op('sum', np.sum, float_frame_with_na, float_frame,
float_string_frame, has_numeric_only=True,
skipna_alternative=np.nansum)
_check_stat_op('sum', np.sum, float_frame_with_na, float_frame,
float_string_frame, has_numeric_only=True,
skipna_alternative=np.nansum)

# mixed types (with upcasting happening)
self._check_stat_op('sum', np.sum,
mixed_float_frame.astype('float32'), float_frame,
float_string_frame, has_numeric_only=True,
check_dtype=False, check_less_precise=True)
_check_stat_op('sum', np.sum,
mixed_float_frame.astype('float32'), float_frame,
float_string_frame, has_numeric_only=True,
check_dtype=False, check_less_precise=True)

@pytest.mark.parametrize('method', ['sum' 8000 , 'mean', 'prod', 'var',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in follow, can use these fixtures (may need to make small changes) when #22762 is merged

'std', 'skew', 'min', 'max'])
Expand All @@ -679,13 +679,13 @@ def test_stat_operators_attempt_obj_array(self, method):
tm.assert_series_equal(result, expected)

def test_mean(self, float_frame_with_na, float_frame, float_string_frame):
self._check_stat_op('mean', np.mean, float_frame_with_na,
float_frame, float_string_frame, check_dates=True)
_check_stat_op('mean', np.mean, float_frame_with_na,
float_frame, float_string_frame, check_dates=True)

def test_product(self, float_frame_with_na, float_frame,
float_string_frame):
self._check_stat_op('product', np.prod, float_frame_with_na,
float_frame, float_string_frame)
_check_stat_op('product', np.prod, float_frame_with_na,
float_frame, float_string_frame)

# TODO: Ensure warning isn't emitted in the first place
@pytest.mark.filterwarnings("ignore:All-NaN:RuntimeWarning")
Expand All @@ -696,18 +696,18 @@ def wrapper(x):
return np.nan
return np.median(x)

self._check_stat_op('median', wrapper, float_frame_with_na,
float_frame, float_string_frame, check_dates=True)
_check_stat_op('median', wrapper, float_frame_with_na,
float_frame, float_string_frame, check_dates=True)

def test_min(self, float_frame_with_na, int_frame,
float_frame, float_string_frame):
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore", RuntimeWarning)
self._check_stat_op('min', np.min, float_frame_with_na,
float_frame, float_string_frame,
check_dates=True)
self._check_stat_op('min', np.min, int_frame, float_frame,
float_string_frame)
_check_stat_op('min', np.min, float_frame_with_na,
float_frame, float_string_frame,
check_dates=True)
_check_stat_op('min', np.min, int_frame, float_frame,
float_string_frame)

def test_cummin(self, datetime_frame):
datetime_frame.loc[5:10, 0] = nan
Expand Down Expand Up @@ -759,26 +759,26 @@ def test_max(self, float_frame_with_na, int_frame,
float_frame, float_string_frame):
with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore", RuntimeWarning)
self._check_stat_op('max', np.max, float_frame_with_na,
float_frame, float_string_frame,
check_dates=True)
self._check_stat_op('max', np.max, int_frame, float_frame,
float_string_frame)
_check_stat_op('max', np.max, float_frame_with_na,
float_frame, float_string_frame,
check_dates=True)
_check_stat_op('max', np.max, int_frame, float_frame,
float_string_frame)

def test_mad(self, float_frame_with_na, float_frame, float_string_frame):
f = lambda x: np.abs(x - x.mean()).mean()
self._check_stat_op('mad', f, float_frame_with_na, float_frame,
float_string_frame)
_check_stat_op('mad', f, float_frame_with_na, float_frame,
float_string_frame)

def test_var_std(self, float_frame_with_na, datetime_frame, float_frame,
float_string_frame):
alt = lambda x: np.var(x, ddof=1)
self._check_stat_op('var', alt, float_frame_with_na, float_frame,
float_string_frame)
_check_stat_op('var', alt, float_frame_with_na, float_frame,
float_string_frame)

alt = lambda x: np.std(x, ddof=1)
self._check_stat_op('std', alt, float_frame_with_na, float_frame,
float_string_frame)
_check_stat_op('std', alt, float_frame_with_na, float_frame,
float_string_frame)

result = datetime_frame.std(ddof=4)
expected = datetime_frame.apply(lambda x: x.std(ddof=4))
Expand Down Expand Up @@ -892,8 +892,8 @@ def test_cumprod(self, datetime_frame):
def test_sem(self, float_frame_with_na, datetime_frame,
float_frame, float_string_frame):
alt = lambda x: np.std(x, ddof=1) / np.sqrt(len(x))
self._check_stat_op('sem', alt, float_frame_with_na,
float_frame, float_string_frame)
_check_stat_op('sem', alt, float_frame_with_na,
float_frame, float_string_frame)

result = datetime_frame.sem(ddof=4)
expected = datetime_frame.apply(
Expand All @@ -917,8 +917,8 @@ def alt(x):
return np.nan
return skew(x, bias=False)

self._check_stat_op('skew', alt, float_frame_with_na,
float_frame, float_string_frame)
_check_stat_op('skew', alt, float_frame_with_na,
float_frame, float_string_frame)

@td.skip_if_no_scipy
def test_kurt(self, float_frame_with_na, float_frame, float_string_frame):
Expand All @@ -929,8 +929,8 @@ def alt(x):
return np.nan
return kurtosis(x, bias=False)

self._check_stat_op('kurt', alt, float_frame_with_na,
float_frame, float_string_frame)
_check_stat_op('kurt', alt, float_frame_with_na,
float_frame, float_string_frame)

index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]],
8000 labels=[[0, 0, 0, 0, 0, 0],
Expand Down Expand Up @@ -1205,9 +1205,9 @@ def wrapper(x):
return np.nan
return np.median(x)

self._check_stat_op('median', wrapper, int_frame, float_frame,
float_string_frame, check_dtype=False,
check_dates=True)
_check_stat_op('median', wrapper, int_frame, float_frame,
float_string_frame, check_dtype=False,
check_dates=True)

# Miscellanea

Expand Down Expand Up @@ -1263,12 +1263,12 @@ def test_idxmax(self, float_frame, int_frame):
# Logical reductions

def test_any_all(self, bool_frame_with_na, float_string_frame):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can parameterize on ['all', 'any'] (use getattr(np, name) in side

self._check_bool_op('any', np.any, bool_frame_with_na,
float_string_frame, has_skipna=True,
has_bool_only=True)
self._check_bool_op('all', np.all, bool_frame_with_na,
float_string_frame, has_skipna=True,
has_bool_only=True)
_check_bool_op('any', np.any, bool_frame_with_na,
float_string_frame, has_skipna=True,
has_bool_only=True)
_check_bool_op('all', np.all, bool_frame_with_na,
float_string_frame, has_skipna=True,
has_bool_only=True)

def test_any_all_extra(self):
df = DataFrame({
Expand Down
0