-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: {expanding,rolling}_{cov,corr} don't handle arguments with different index sets properly #7604
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why was this changed?
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.
The expanding_xxx() functions need window = len(arg1) + len(arg2) rather than = max(len(arg1), len(arg2)) because once arg1 and arg2 are merged the result could be of length up to len(arg1) + len(arg2) if there is no overlap between the index (or major_axis) of arg1 and arg2. If the index of one is a subset of the index of the other, then max() will be fine; but in general when neither is a subset of the other max() will be too small.
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.
For example, without this fix, see the following; whereas the final value should be 1.
There isn't quite a test for this. I think I should add one.
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.
why would u not align the 2 objects before you start, then all this is moot
eg try doing
df1, df2 = df1.align(df2)
and see what that results
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.
No idea. This is the way it was written, and I didn't want to modify things any more than necessary.
At the very least I will add a test, and will see if the .align() thing works. Probably won't get it done until tomorrow.
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.
Replacing:
with:
in expanding_cov/corr() works for series, but not for data frames: it not only merges the index, but also the columns, thus producing the wrong result for pairwise=True calls -- e.g. if arg1.columns=['A','B'] and arg2.columns=['X','Y'], then while the result should have major/minor axes ['A','B'] and ['X','Y'], instead it ends up with both being ['A','B','X','Y'].
At any rate, since the two objects end up being aligned anyway in _flex_binary_moment(), aligning them in expanding_cov/corr is just redundant.
I updated the code to include several additional tests, but left window = len(arg1) + len(arg2) unchanged.