-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
jreback
merged 15 commits into
pandas-dev:master
from
h-vetinari:fixturize_frame_analytics
Oct 6, 2018
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d23ac16
Fixturize frame/test_analytics.py
h-vetinari 485e0d8
Review (WillAyd)
h-vetinari f1a394a
Revert disambiguating underscores
h-vetinari 7ac476e
Pure copy/paste of _check_stat_op and _check_bool_op
h-vetinari e1a8c5a
Pure unindent of _check_stat_op and _check_bool_op
h-vetinari 6c4a702
Make _check_stat_op and _check_bool_op run
h-vetinari 98f3243
Correctly group tests within _check_[stat/bool]_op
h-vetinari b043bb4
Consistent naming of parameters
h-vetinari 4a2adeb
Break up _check_[stat/bool]_op
h-vetinari 56020d7
Final touches
h-vetinari c07c5ed
Merge remote-tracking branch 'upstream/master' into fixturize_frame_a…
h-vetinari 7a56cfb
Revert "Final touches"
h-vetinari e197fe7
Revert "Break up _check_[stat/bool]_op"
h-vetinari 48272d9
Revert "Consistent naming of parameters"
h-vetinari c227fa2
Revert "Correctly group tests within _check_[stat/bool]_op"
h-vetinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make _check_stat_op and _check_bool_op run
- Loading branch information
commit 6c4a7027b0bfe64f72a6ac4831f94eee15406567
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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) | ||
|
@@ -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() | ||
|
@@ -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], | ||
|
@@ -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', | ||
'std', 'skew', 'min', 'max']) | ||
|
@@ -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") | ||
|
@@ -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 | ||
|
@@ -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)) | ||
|
@@ -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( | ||
|
@@ -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): | ||
|
@@ -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], | ||
|
@@ -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 | ||
|
||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can parameterize on ['all', 'any'] (use |
||
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({ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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