Skip to content

Commit 37a4f4f

Browse files
BUG: Fix rolling.corr with time frequency (pandas-dev#31841) (pandas-dev#32094)
Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 5e38842 commit 37a4f4f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v1.0.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Fixed regressions
1818
- Fixed regression in :meth:`DataFrame.to_excel` when ``columns`` kwarg is passed (:issue:`31677`)
1919
- Fixed regression in :meth:`Series.align` when ``other`` is a DataFrame and ``method`` is not None (:issue:`31785`)
2020
- Fixed regression in :meth:`pandas.core.groupby.RollingGroupby.apply` where the ``raw`` parameter was ignored (:issue:`31754`)
21+
- Fixed regression in :meth:`rolling(..).corr() <pandas.core.window.Rolling.corr>` when using a time offset (:issue:`31789`)
2122
-
2223

2324
.. ---------------------------------------------------------------------------

pandas/core/window/rolling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ def corr(self, other=None, pairwise=None, **kwargs):
17821782
# only default unset
17831783
pairwise = True if pairwise is None else pairwise
17841784
other = self._shallow_copy(other)
1785-
window = self._get_window(other)
1785+
window = self._get_window(other) if not self.is_freq_type else self.win_freq
17861786

17871787
def _get_corr(a, b):
17881788
a = a.rolling(

pandas/tests/window/test_pairwise.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import warnings
22

3+
import numpy as np
34
import pytest
45

5-
from pandas import DataFrame, Series
6+
from pandas import DataFrame, Series, date_range
67
import pandas._testing as tm
78
from pandas.core.algorithms import safe_sort
89

@@ -181,3 +182,10 @@ def test_pairwise_with_series(self, f):
181182
for i, result in enumerate(results):
182183
if i > 0:
183184
self.compare(result, results[0])
185+
186+
def test_corr_freq_memory_error(self):
187+
# GH 31789
188+
s = Series(range(5), index=date_range("2020", periods=5))
189+
result = s.rolling("12H").corr(s)
190+
expected = Series([np.nan] * 5, index=date_range("2020", periods=5))
191+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)