Skip to content

Commit a68c947

Browse files
committed
Add failing test reproducing groupby-resample KeyError (#50840)
1 parent 99bda74 commit a68c947

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/resample/test_resampler_grouper.py

+30
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,33 @@ def test_groupby_resample_size_all_index_same():
537537
),
538538
)
539539
tm.assert_series_equal(result, expected)
540+
541+
542+
def test_groupby_resample_on_index_with_list_of_keys():
543+
# GH 50840
544+
df = DataFrame(
545+
data={
546+
"group": [0, 0, 0, 0, 1, 1, 1, 1],
547+
"val": [3, 1, 4, 1, 5, 9, 2, 6],
548+
},
549+
index=Series(
550+
date_range(start="2016-01-01", periods=8),
551+
name="date",
552+
),
553+
)
554+
result = df.groupby("group").resample("2D")[["val"]].mean()
555+
expected = DataFrame(
556+
data={
557+
"val": [2.0, 2.5, 7.0, 4.0],
558+
},
559+
index=Index(
560+
data=[
561+
(0, Timestamp("2016-01-01")),
562+
(0, Timestamp("2016-01-03")),
563+
(1, Timestamp("2016-01-05")),
564+
(1, Timestamp("2016-01-07")),
565+
],
566+
name=("group", "date"),
567+
),
568+
)
569+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)