Skip to content

Commit f05eb7f

Browse files
TST/REF: Deprivate check_pairwise_moment and remove ConsistencyBase (pandas-dev#34119)
1 parent ac9bc76 commit f05eb7f

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

pandas/tests/window/common.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ def _create_data(self):
2424
self.frame = DataFrame(randn(N, K), index=self.rng, columns=np.arange(K))
2525

2626

27-
class ConsistencyBase(Base):
28-
def _create_data(self):
29-
super()._create_data()
30-
31-
def _check_pairwise_moment(self, dispatch, name, **kwargs):
32-
def get_result(obj, obj2=None):
33-
return getattr(getattr(obj, dispatch)(**kwargs), name)(obj2)
34-
35-
result = get_result(self.frame)
36-
result = result.loc[(slice(None), 1), 5]
37-
result.index = result.index.droplevel(1)
38-
expected = get_result(self.frame[1], self.frame[5])
39-
expected.index = expected.index._with_freq(None)
40-
tm.assert_series_equal(result, expected, check_names=False)
27+
def check_pairwise_moment(frame, dispatch, name, **kwargs):
28+
def get_result(obj, obj2=None):
29+
return getattr(getattr(obj, dispatch)(**kwargs), name)(obj2)
30+
31+
result = get_result(frame)
32+
result = result.loc[(slice(None), 1), 5]
33+
result.index = result.index.droplevel(1)
34+
expected = get_result(frame[1], frame[5])
35+
expected.index = expected.index._with_freq(None)
36+
tm.assert_series_equal(result, expected, check_names=False)
4137

4238

4339
def ew_func(A, B, com, name, **kwargs):

pandas/tests/window/moments/test_moments_ewm.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import pandas._testing as tm
88
from pandas.tests.window.common import (
99
Base,
10-
ConsistencyBase,
1110
check_binary_ew,
1211
check_binary_ew_min_periods,
12+
check_pairwise_moment,
1313
ew_func,
1414
moments_consistency_cov_data,
1515
moments_consistency_is_constant,
@@ -274,15 +274,13 @@ def test_ew_min_periods(self, min_periods, name):
274274
assert result2.dtype == np.float_
275275

276276

277-
class TestEwmMomentsConsistency(ConsistencyBase):
277+
class TestEwmMomentsConsistency(Base):
278278
def setup_method(self, method):
279279
self._create_data()
280280

281-
def test_ewmcov_pairwise(self):
282-
self._check_pairwise_moment("ewm", "cov", span=10, min_periods=5)
283-
284-
def test_ewmcorr_pairwise(self):
285-
self._check_pairwise_moment("ewm", "corr", span=10, min_periods=5)
281+
@pytest.mark.parametrize("func", ["cov", "corr"])
282+
def test_ewm_pairwise_cov_corr(self, func):
283+
check_pairwise_moment(self.frame, "ewm", func, span=10, min_periods=5)
286284

287285

288286
@pytest.mark.parametrize("name", ["cov", "corr"])

pandas/tests/window/moments/test_moments_expanding.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pandas import DataFrame, Index, MultiIndex, Series, isna, notna
88
import pandas._testing as tm
99
from pandas.tests.window.common import (
10-
ConsistencyBase,
10+
Base,
1111
moments_consistency_cov_data,
1212
moments_consistency_is_constant,
1313
moments_consistency_mock_mean,
@@ -18,7 +18,7 @@
1818
)
1919

2020

21-
class TestExpandingMomentsConsistency(ConsistencyBase):
21+
class TestExpandingMomentsConsistency(Base):
2222
def setup_method(self, method):
2323
self._create_data()
2424

pandas/tests/window/moments/test_moments_rolling.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.core.window.common import _flex_binary_moment
1515
from pandas.tests.window.common import (
1616
Base,
17-
ConsistencyBase,
17+
check_pairwise_moment,
1818
moments_consistency_cov_data,
1919
moments_consistency_is_constant,
2020
moments_consistency_mock_mean,
@@ -942,7 +942,7 @@ def _rolling_consistency_cases():
942942
yield window, min_periods, center
943943

944944

945-
class TestRollingMomentsConsistency(ConsistencyBase):
945+
class TestRollingMomentsConsistency(Base):
946946
def setup_method(self, method):
947947
self._create_data()
948948

@@ -954,9 +954,6 @@ def test_rolling_cov(self):
954954
result = A.rolling(window=50, min_periods=25).cov(B)
955955
tm.assert_almost_equal(result[-1], np.cov(A[-50:], B[-50:])[0, 1])
956956

957-
def test_rolling_cov_pairwise(self):
958-
self._check_pairwise_moment("rolling", "cov", window=10, min_periods=5)
959-
960957
def test_rolling_corr(self):
961958
A = self.series
962959
B = A + randn(len(A))
@@ -973,8 +970,9 @@ def test_rolling_corr(self):
973970
result = a.rolling(window=len(a), min_periods=1).corr(b)
974971
tm.assert_almost_equal(result[-1], a.corr(b))
975972

976-
def test_rolling_corr_pairwise(self):
977-
self._check_pairwise_moment("rolling", "corr", window=10, min_periods=5)
973+
@pytest.mark.parametrize("func", ["cov", "corr"])
974+
def test_rolling_pairwise_cov_corr(self, func):
975+
check_pairwise_moment(self.frame, "rolling", func, window=10, min_periods=5)
978976

979977
@pytest.mark.parametrize("method", ["corr", "cov"])
980978
def test_flex_binary_frame(self, method):

0 commit comments

Comments
 (0)