-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Incorrect handling of rolling.cov with offset window #16244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pandas/tests/test_window.py
Outdated
@@ -3396,6 +3396,18 @@ def test_min_periods(self): | |||
result = df.rolling('2s', min_periods=1).sum() | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_cov(self): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment with the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
d782f55
to
001a88b
Compare
Codecov Report
@@ Coverage Diff @@
## master #16244 +/- ##
==========================================
+ Coverage 90.34% 90.35% +<.01%
==========================================
Files 164 164
Lines 50890 50894 +4
==========================================
+ Hits 45977 45984 +7
+ Misses 4913 4910 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16244 +/- ##
==========================================
+ Coverage 90.34% 90.35% +<.01%
==========================================
Files 164 164
Lines 50890 50894 +4
==========================================
+ Hits 45977 45984 +7
+ Misses 4913 4910 -3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16244 +/- ##
==========================================
+ Coverage 90.79% 90.8% +<.01%
==========================================
Files 161 161
Lines 51063 51067 +4
==========================================
+ Hits 46365 46369 +4
Misses 4698 4698
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the test from the issue. I would prefer that instead of comparing the results, you construct the correct results for each case.
add a whatsnew note in 0.20.2 bug fixes / rolling section
pandas/core/window.py
Outdated
@@ -996,7 +997,10 @@ def cov(self, other=None, pairwise=None, ddof=1, **kwargs): | |||
# only default unset | |||
pairwise = True if pairwise is None else pairwise | |||
other = self._shallow_copy(other) | |||
window = self._get_window(other) | |||
if self.is_freq_type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do this in _get_window
itself i think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried changing _get_window
, but a lot of methods (such as var
, median
, and sum
) require an integer window and seem to be working fine right now. If this issue is not a problem in methods other than cov
, changing the code only for cov
seems to make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test for issue and whatsnew note added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here (1-line) about this
0e6ccaf
to
76024c1
Compare
idx = pd.date_range('2017-01-01', periods=24, freq='1h') | ||
ss = pd.Series(np.arange(len(idx)), index=idx) | ||
|
||
result = ss.rolling('2h').cov() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also test again using ss.rolling(2).cov()
(will be the same for this case).
I don't know if we have any tests for a non-regular date range, where freq=2
and freq='2h'
are actually different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test added
76024c1
to
1c34441
Compare
1c34441
to
a5582ec
Compare
Rebased. @jreback I think everything was addressed, if you want to verify? |
thanks! |
(cherry picked from commit 4ca29f4)
Version 0.20.2 * tag 'v0.20.2': (68 commits) RLS: v0.20.2 DOC: Update release.rst DOC: Whatsnew fixups (pandas-dev#16596) ERRR: Raise error in usecols when column doesn't exist but length matches (pandas-dev#16460) BUG: convert numpy strings in index names in HDF pandas-dev#13492 (pandas-dev#16444) PERF: vectorize _interp_limit (pandas-dev#16592) DOC: whatsnew 0.20.2 edits (pandas-dev#16587) API: Make is_strictly_monotonic_* private (pandas-dev#16576) BUG: reimplement MultiIndex.remove_unused_levels (pandas-dev#16565) Strictly monotonic (pandas-dev#16555) ENH: add .ngroup() method to groupby objects (pandas-dev#14026) (pandas-dev#14026) fix linting BUG: Incorrect handling of rolling.cov with offset window (pandas-dev#16244) BUG: select_as_multiple doesn't respect start/stop kwargs GH16209 (pandas-dev#16317) return empty MultiIndex for symmetrical difference on equal MultiIndexes (pandas-dev#16486) BUG: Bug in .resample() and .groupby() when aggregating on integers (pandas-dev#16549) BUG: Fixed tput output on windows (pandas-dev#16496) Strictly monotonic (pandas-dev#16555) BUG: fixed wrong order of ordered labels in pd.cut() BUG: Fixed to_html ignoring index_names parameter ...
git diff upstream/master --name-only -- '*.py' | flake8 --diff