From 076c2a46d5946fe4fc1f171abbe589f98616725e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 10 Feb 2020 09:51:31 -0800 Subject: [PATCH] BUG: Fix rolling.corr with time frequency (#31841) * BUG: Fix rolling.corr with time frequency * Add extra tick in whatsnew * Clarify whatsnew --- doc/source/whatsnew/v1.0.2.rst | 1 + pandas/core/window/rolling.py | 2 +- pandas/tests/window/test_pairwise.py | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index 805f87b63eef8..6bbaa4a883d0e 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -17,6 +17,7 @@ Fixed regressions - Fixed regression in :meth:`DataFrame.to_excel` when ``columns`` kwarg is passed (:issue:`31677`) - Fixed regression in :meth:`Series.align` when ``other`` is a DataFrame and ``method`` is not None (:issue:`31785`) +- Fixed regression in :meth:`rolling(..).corr() ` when using a time offset (:issue:`31789`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index c1e34757b45d4..235d3520d4ab9 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -1781,7 +1781,7 @@ def corr(self, other=None, pairwise=None, **kwargs): # only default unset pairwise = True if pairwise is None else pairwise other = self._shallow_copy(other) - window = self._get_window(other) + window = self._get_window(other) if not self.is_freq_type else self.win_freq def _get_corr(a, b): a = a.rolling( diff --git a/pandas/tests/window/test_pairwise.py b/pandas/tests/window/test_pairwise.py index 717273cff64ea..bb305e93a3cf1 100644 --- a/pandas/tests/window/test_pairwise.py +++ b/pandas/tests/window/test_pairwise.py @@ -1,8 +1,9 @@ import warnings +import numpy as np import pytest -from pandas import DataFrame, Series +from pandas import DataFrame, Series, date_range import pandas._testing as tm from pandas.core.algorithms import safe_sort @@ -181,3 +182,10 @@ def test_pairwise_with_series(self, f): for i, result in enumerate(results): if i > 0: self.compare(result, results[0]) + + def test_corr_freq_memory_error(self): + # GH 31789 + s = Series(range(5), index=date_range("2020", periods=5)) + result = s.rolling("12H").corr(s) + expected = Series([np.nan] * 5, index=date_range("2020", periods=5)) + tm.assert_series_equal(result, expected)