-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST/REF: Fixturize constant functions in ConsistencyBase #33943
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
Changes from 19 commits
7e461a1
1314059
8bcb313
24c3ede
dea38f2
cd9e7ac
e5e912b
045a76f
800ec58
d37b2c7
494f94c
15188fc
8f32d5f
4918552
6bf8c7f
88d8439
a8c9bac
384844b
ddc8160
a602629
27b50c6
2a485e1
abf3276
7b58306
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,50 +145,52 @@ def _check_expanding_has_min_periods(self, func, static_comp, has_min_periods): | |
result = func(ser) | ||
tm.assert_almost_equal(result.iloc[-1], static_comp(ser[:50])) | ||
|
||
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4]) | ||
def test_expanding_apply_consistency(self, consistency_data, min_periods): | ||
x, is_constant, no_nans = consistency_data | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings( | ||
"ignore", | ||
message=".*(empty slice|0 for slice).*", | ||
category=RuntimeWarning, | ||
) | ||
# test consistency between expanding_xyz() and either (a) | ||
# expanding_apply of Series.xyz(), or (b) expanding_apply of | ||
# np.nanxyz() | ||
functions = self.base_functions | ||
|
||
# GH 8269 | ||
if no_nans: | ||
functions = self.base_functions + self.no_nan_functions | ||
for (f, require_min_periods, name) in functions: | ||
expanding_f = getattr(x.expanding(min_periods=min_periods), name) | ||
|
||
if ( | ||
require_min_periods | ||
and (min_periods is not None) | ||
and (min_periods < require_min_periods) | ||
): | ||
continue | ||
|
||
if name == "count": | ||
expanding_f_result = expanding_f() | ||
expanding_apply_f_result = x.expanding(min_periods=0).apply( | ||
func=f, raw=True | ||
) | ||
|
||
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4]) | ||
def test_expanding_apply_consistency( | ||
consistency_data, base_functions, no_nan_functions, min_periods | ||
): | ||
x, is_constant, no_nans = consistency_data | ||
|
||
with warnings.catch_warnings(): | ||
warnings.filterwarnings( | ||
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning, | ||
) | ||
# test consistency between expanding_xyz() and either (a) | ||
# expanding_apply of Series.xyz(), or (b) expanding_apply of | ||
# np.nanxyz() | ||
functions = base_functions | ||
|
||
# GH 8269 | ||
if no_nans: | ||
functions = base_functions + no_nan_functions | ||
for (f, require_min_periods, name) in functions: | ||
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. e.g in an ideal case we don't have this loop here 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. now it may be that this increases the number of tests by 10x so we don'twant to do this, but have a look see 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. yeah, refer to the comment above 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. yep sounds good |
||
expanding_f = getattr(x.expanding(min_periods=min_periods), name) | ||
|
||
if ( | ||
require_min_periods | ||
and (min_periods is not None) | ||
and (min_periods < require_min_periods) | ||
): | ||
continue | ||
|
||
if name == "count": | ||
expanding_f_result = expanding_f() | ||
expanding_apply_f_result = x.expanding(min_periods=0).apply( | ||
func=f, raw=True | ||
) | ||
else: | ||
if name in ["cov", "corr"]: | ||
expanding_f_result = expanding_f(pairwise=False) | ||
else: | ||
if name in ["cov", "corr"]: | ||
expanding_f_result = expanding_f(pairwise=False) | ||
else: | ||
expanding_f_result = expanding_f() | ||
expanding_apply_f_result = x.expanding( | ||
min_periods=min_periods | ||
).apply(func=f, raw=True) | ||
|
||
# GH 9422 | ||
if name in ["sum", "prod"]: | ||
tm.assert_equal(expanding_f_result, expanding_apply_f_result) | ||
expanding_f_result = expanding_f() | ||
expanding_apply_f_result = x.expanding(min_periods=min_periods).apply( | ||
func=f, raw=True | ||
) | ||
|
||
# GH 9422 | ||
if name in ["sum", "prod"]: | ||
tm.assert_equal(expanding_f_result, expanding_apply_f_result) | ||
|
||
|
||
@pytest.mark.parametrize("min_periods", [0, 1, 2, 3, 4]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -946,58 +946,6 @@ class TestRollingMomentsConsistency(ConsistencyBase): | |
def setup_method(self, method): | ||
self._create_data() | ||
|
||
@pytest.mark.parametrize( | ||
"window,min_periods,center", list(_rolling_consistency_cases()) | ||
) | ||
def test_rolling_apply_consistency( | ||
self, consistency_data, window, min_periods, center | ||
): | ||
x, is_constant, no_nans = consistency_data | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings( | ||
"ignore", | ||
message=".*(empty slice|0 for slice).*", | ||
category=RuntimeWarning, | ||
) | ||
# test consistency between rolling_xyz() and either (a) | ||
# rolling_apply of Series.xyz(), or (b) rolling_apply of | ||
# np.nanxyz() | ||
functions = self.base_functions | ||
|
||
# GH 8269 | ||
if no_nans: | ||
functions = self.base_functions + self.no_nan_functions | ||
for (f, require_min_periods, name) in functions: | ||
rolling_f = getattr( | ||
x.rolling(window=window, center=center, min_periods=min_periods), | ||
name, | ||
) | ||
|
||
if ( | ||
require_min_periods | ||
and (min_periods is not None) | ||
and (min_periods < require_min_periods) | ||
): | ||
continue | ||
|
||
if name == "count": | ||
rolling_f_result = rolling_f() | ||
rolling_apply_f_result = x.rolling( | ||
window=window, min_periods=min_periods, center=center | ||
).apply(func=f, raw=True) | ||
else: | ||
if name in ["cov", "corr"]: | ||
rolling_f_result = rolling_f(pairwise=False) | ||
else: | ||
rolling_f_result = rolling_f() | ||
rolling_apply_f_result = x.rolling( | ||
window=window, min_periods=min_periods, center=center | ||
).apply(func=f, raw=True) | ||
|
||
# GH 9422 | ||
if name in ["sum", "prod"]: | ||
tm.assert_equal(rolling_f_result, rolling_apply_f_result) | ||
|
||
# binary moments | ||
def test_rolling_cov(self): | ||
A = self.series | ||
|
@@ -1052,6 +1000,58 @@ def test_flex_binary_frame(self, method): | |
tm.assert_frame_equal(res3, exp) | ||
|
||
|
||
@pytest.mark.slow | ||
@pytest.mark.parametrize( | ||
"window,min_periods,center", list(_rolling_consistency_cases()) | ||
) | ||
def test_rolling_apply_consistency( | ||
consistency_data, base_functions, no_nan_functions, window, min_periods, center | ||
): | ||
x, is_constant, no_nans = consistency_data | ||
|
||
with warnings.catch_warnings(): | ||
warnings.filterwarnings( | ||
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning, | ||
) | ||
# test consistency between rolling_xyz() and either (a) | ||
# rolling_apply of Series.xyz(), or (b) rolling_apply of | ||
# np.nanxyz() | ||
functions = base_functions | ||
|
||
# GH 8269 | ||
if no_nans: | ||
functions = no_nan_functions + base_functions | ||
for (f, require_min_periods, name) in functions: | ||
rolling_f = getattr( | ||
x.rolling(window=window, center=center, min_periods=min_periods), name, | ||
) | ||
|
||
if ( | ||
require_min_periods | ||
and (min_periods is not None) | ||
and (min_periods < require_min_periods) | ||
): | ||
continue | ||
|
||
if name == "count": | ||
rolling_f_result = rolling_f() | ||
rolling_apply_f_result = x.rolling( | ||
window=window, min_periods=min_periods, center=center | ||
).apply(func=f, raw=True) | ||
else: | ||
if name in ["cov", "corr"]: | ||
rolling_f_result = rolling_f(pairwise=False) | ||
else: | ||
rolling_f_result = rolling_f() | ||
rolling_apply_f_result = x.rolling( | ||
window=window, min_periods=min_periods, center=center | ||
).apply(func=f, raw=True) | ||
|
||
# GH 9422 | ||
if name in ["sum", "prod"]: | ||
tm.assert_equal(rolling_f_result, rolling_apply_f_result) | ||
|
||
|
||
@pytest.mark.parametrize("window", range(7)) | ||
def test_rolling_corr_with_zero_variance(window): | ||
# GH 18430 | ||
|
@@ -1477,6 +1477,7 @@ def test_rolling_consistency_std(consistency_data, window, min_periods, center): | |
) | ||
|
||
|
||
@pytest.mark.slow | ||
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. @jbrockmendel since this change is very tiny, i think it is okay to just change it here although it is out of scope of this PR. |
||
@pytest.mark.parametrize( | ||
"window,min_periods,center", list(_rolling_consistency_cases()) | ||
) | ||
|
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.
can you document the tuples here (e.g. what they refer to)
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.
yep, i added in the docs