Skip to content

Commit 3b18c35

Browse files
code sample for pandas-dev#46061
1 parent f41f475 commit 3b18c35

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bisect/46061.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BUG: groupby().rolling("freq") validation raises even if dates are sorted within each group #46061
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
test_df = pd.DataFrame(
7+
{
8+
"Name": ["L", "L", "L", "M", "M", "M", "M", "M", "M"],
9+
"ID": ["L1", "L2", "L3", "M1", "M2", "M3", "M4", "M5", "M6"],
10+
"Date": [
11+
"2005-01-01",
12+
"2006-01-01",
13+
"2013-01-01",
14+
"2005-01-01",
15+
"2006-01-01",
16+
"2006-01-01",
17+
"2017-01-01",
18+
"2006-02-01",
19+
"2006-03-01",
20+
],
21+
"indicator": [0, 1, 0, 0, 1, 0, 0, 1, 0],
22+
"rolling_sum": [0, 0, 1, 0, 0, 0, 0, 1, 2],
23+
}
24+
)
25+
test_df["Date"] = pd.to_datetime(test_df["Date"], errors="coerce")
26+
27+
grp = test_df.groupby("Name").rolling("731D", on="Date")
28+
29+
print(grp)
30+
# grp["indicator"].sum().reset_index()

0 commit comments

Comments
 (0)