Skip to content

Commit 076c2a4

Browse files
mroeschkejorisvandenbossche
authored andcommitted
BUG: Fix rolling.corr with time frequency (pandas-dev#31841)
* BUG: Fix rolling.corr with time frequency * Add extra tick in whatsnew * Clarify whatsnew
1 parent e3044d5 commit 076c2a4

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
@@ -17,6 +17,7 @@ Fixed regressions
1717

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`)
20+
- Fixed regression in :meth:`rolling(..).corr() <pandas.core.window.Rolling.corr>` when using a time offset (:issue:`31789`)
2021
-
2122

2223
.. ---------------------------------------------------------------------------

pandas/core/window/rolling.py

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

17861786
def _get_corr(a, b):
17871787
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)