From 53f6c82c58a919585acdbb352aef101bb274846e Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 9 Feb 2020 20:24:00 -0800 Subject: [PATCH 1/3] BUG: Fix rolling.corr with time frequency --- doc/source/whatsnew/v1.0.2.rst | 2 +- pandas/core/window/rolling.py | 2 +- pandas/tests/window/test_pairwise.py | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index b055b44274bd8..60abf12506320 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -17,7 +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:`pandas.core.window.Rolling.corr` when using a time offset (:issue:`31789`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 580c7cc0554d0..f7ba4105c363c 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) From f97f686e6549950c0d51797592263dd5da93ac06 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 9 Feb 2020 20:25:46 -0800 Subject: [PATCH 2/3] Add extra tick in whatsnew --- doc/source/whatsnew/v1.0.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index 60abf12506320..b7978b584a7f0 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -18,6 +18,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:`pandas.core.window.Rolling.corr` when using a time offset (:issue:`31789`) +- .. --------------------------------------------------------------------------- From 527ef7ce65f061b020d812098a161587abf542b8 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Mon, 10 Feb 2020 08:26:34 -0800 Subject: [PATCH 3/3] Clarify whatsnew --- doc/source/whatsnew/v1.0.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.2.rst b/doc/source/whatsnew/v1.0.2.rst index b801da33bd29f..f4bb8c580fb08 100644 --- a/doc/source/whatsnew/v1.0.2.rst +++ b/doc/source/whatsnew/v1.0.2.rst @@ -18,7 +18,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:`pandas.core.groupby.RollingGroupby.apply` where the ``raw`` parameter was ignored (:issue:`31754`) -- Fixed regression in :meth:`pandas.core.window.Rolling.corr` when using a time offset (:issue:`31789`) +- Fixed regression in :meth:`rolling(..).corr() ` when using a time offset (:issue:`31789`) - .. ---------------------------------------------------------------------------