-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix Rolling where duplicate datetimelike indexes are treated as consecutive rather than equal with closed='left' and closed='neither' #54917
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
mroeschke
merged 8 commits into
pandas-dev:main
from
ihsansecer:bugfix-rolling-datetimelike-nonunique
Sep 5, 2023
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b751a7
Add bugfix for rolling window with nonunique datetimelike index
ihsansecer 8d9ce73
Run black
ihsansecer dc61063
Add entry to whatsnew
ihsansecer 4f35883
Fix VariableOffsetWindowIndexer
ihsansecer 8cb8499
Simplify change in indexers.pyx
ihsansecer 8b6684b
Add test
ihsansecer 2806599
Merge branch 'main' into bugfix-rolling-datetimelike-nonunique
ihsansecer b459ad7
Merge branch 'main' into bugfix-rolling-datetimelike-nonunique
ihsansecer 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,20 +466,23 @@ def test_groupby_rolling_subset_with_closed(self): | |
# GH 35549 | ||
df = DataFrame( | ||
{ | ||
"column1": range(6), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified these two tests as the result would be list of nan values |
||
"column2": range(6), | ||
"group": 3 * ["A", "B"], | ||
"date": [Timestamp("2019-01-01")] * 6, | ||
"column1": range(8), | ||
"column2": range(8), | ||
"group": ["A"] * 4 + ["B"] * 4, | ||
"date": [ | ||
Timestamp(date) | ||
for date in ["2019-01-01", "2019-01-01", "2019-01-02", "2019-01-02"] | ||
] | ||
* 2, | ||
} | ||
) | ||
result = ( | ||
df.groupby("group").rolling("1D", on="date", closed="left")["column1"].sum() | ||
) | ||
expected = Series( | ||
[np.nan, 0.0, 2.0, np.nan, 1.0, 4.0], | ||
index=MultiIndex.from_tuples( | ||
[("A", Timestamp("2019-01-01"))] * 3 | ||
+ [("B", Timestamp("2019-01-01"))] * 3, | ||
[np.nan, np.nan, 1.0, 1.0, np.nan, np.nan, 9.0, 9.0], | ||
index=MultiIndex.from_frame( | ||
df[["group", "date"]], | ||
names=["group", "date"], | ||
), | ||
name="column1", | ||
|
@@ -490,10 +493,14 @@ def test_groupby_subset_rolling_subset_with_closed(self): | |
# GH 35549 | ||
df = DataFrame( | ||
{ | ||
"column1": range(6), | ||
"column2": range(6), | ||
"group": 3 * ["A", "B"], | ||
"date": [Timestamp("2019-01-01")] * 6, | ||
"column1": range(8), | ||
"column2": range(8), | ||
"group": ["A"] * 4 + ["B"] * 4, | ||
"date": [ | ||
Timestamp(date) | ||
for date in ["2019-01-01", "2019-01-01", "2019-01-02", "2019-01-02"] | ||
] | ||
* 2, | ||
} | ||
) | ||
|
||
|
@@ -503,10 +510,9 @@ def test_groupby_subset_rolling_subset_with_closed(self): | |
.sum() | ||
) | ||
expected = Series( | ||
[np.nan, 0.0, 2.0, np.nan, 1.0, 4.0], | ||
index=MultiIndex.from_tuples( | ||
[("A", Timestamp("2019-01-01"))] * 3 | ||
+ [("B", Timestamp("2019-01-01"))] * 3, | ||
[np.nan, np.nan, 1.0, 1.0, np.nan, np.nan, 9.0, 9.0], | ||
index=MultiIndex.from_frame( | ||
df[["group", "date"]], | ||
names=["group", "date"], | ||
), | ||
name="column1", | ||
|
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.
Could you make a similar test for
VariableOffsetWindowIndexer.get_window_bounds
and include a test?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.
Done