Skip to content

Commit 50c0a03

Browse files
Tobias Brandttobias-aam
authored andcommitted
TST: Added tests for pairwise behaviour in rolling moments.
Added a test for rolling_cov_pairwise similar to the test for rolling_corr_pairwise. Added tests for ewmcov_pairwise and ewmcorr_pairwise. Added test for expanding_cov_pairwise based on the test for expanding_corr_pairwise.
1 parent 1ff776a commit 50c0a03

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

pandas/stats/tests/test_moments.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ def test_rolling_cov(self):
586586
result = mom.rolling_cov(A, B, 50, min_periods=25)
587587
assert_almost_equal(result[-1], np.cov(A[-50:], B[-50:])[0, 1])
588588

589+
def test_rolling_cov_pairwise(self):
590+
self._check_pairwise_moment(mom.rolling_cov_pairwise,
591+
mom.rolling_cov, 10, min_periods=5)
592+
589593
def test_rolling_corr(self):
590594
A = self.series
591595
B = A + randn(len(A))
@@ -603,12 +607,15 @@ def test_rolling_corr(self):
603607
assert_almost_equal(result[-1], a.corr(b))
604608

605609
def test_rolling_corr_pairwise(self):
606-
panel = mom.rolling_corr_pairwise(self.frame, 10, min_periods=5)
610+
self._check_pairwise_moment(mom.rolling_corr_pairwise,
611+
mom.rolling_corr, 10, min_periods=5)
612+
613+
def _check_pairwise_moment(self, func_pairwise, func, *args, **kwargs):
614+
panel = func_pairwise(self.frame, self.frame, *args, **kwargs)
607615

608-
correl = panel.ix[:, 1, 5]
609-
exp = mom.rolling_corr(self.frame[1], self.frame[5],
610-
10, min_periods=5)
611-
tm.assert_series_equal(correl, exp)
616+
actual = panel.ix[:, 1, 5]
617+
expected = func(self.frame[1], self.frame[5], *args, **kwargs)
618+
tm.assert_series_equal(actual, expected)
612619

613620
def test_flex_binary_moment(self):
614621
# GH3155
@@ -666,9 +673,17 @@ def _check(method):
666673
def test_ewmcov(self):
667674
self._check_binary_ew(mom.ewmcov)
668675

676+
def test_ewmcov_pairwise(self):
677+
self._check_pairwise_moment(mom.ewmcov_pairwise, mom.ewmcov, 10,
678+
min_periods=5)
679+
669680
def test_ewmcorr(self):
670681
self._check_binary_ew(mom.ewmcorr)
671682

683+
def test_ewmcorr_pairwise(self):
684+
self._check_pairwise_moment(mom.ewmcorr_pairwise, mom.ewmcorr, 10,
685+
min_periods=5)
686+
672687
def _check_binary_ew(self, func):
673688
A = Series(randn(50), index=np.arange(50))
674689
B = A[2:] + randn(48)
@@ -746,6 +761,16 @@ def test_expanding_cov(self):
746761
def test_expanding_max(self):
747762
self._check_expanding(mom.expanding_max, np.max, preserve_nan=False)
748763

764+
def test_expanding_cov_pairwise(self):
765+
result = mom.expanding_cov_pairwise(self.frame)
766+
767+
rolling_result = mom.rolling_cov_pairwise(self.frame,
768+
len(self.frame),
769+
min_periods=1)
770+
771+
for i in result.items:
772+
assert_almost_equal(result[i], rolling_result[i])
773+
749774
def test_expanding_corr_pairwise(self):
750775
result = mom.expanding_corr_pairwise(self.frame)
751776

0 commit comments

Comments
 (0)