Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 3a20b0e

Browse files
committed
Add failing test reproducing groupby-resample KeyError.
1 parent 659de5f commit 3a20b0e

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
@@ -497,3 +497,33 @@ def test_groupby_resample_with_list_of_keys():
497497
),
498498
)
499499
tm.assert_frame_equal(result, expected)
500+
501+
502+
def test_groupby_resample_on_index_with_list_of_keys():
503+
# GH 47362
504+
df = DataFrame(
505+
data={
506+
"group": [0, 0, 0, 0, 1, 1, 1, 1],
507+
"val": [3, 1, 4, 1, 5, 9, 2, 6],
508+
},
509+
index=Series(
510+
date_range(start="2016-01-01", periods=8),
511+
name="date",
512+
),
513+
)
514+
result = df.groupby("group").resample("2D")[["val"]].mean()
515+
expected = DataFrame(
516+
data={
517+
"val": [2.0, 2.5, 7.0, 4.0],
518+
},
519+
index=Index(
520+
data=[
521+
(0, Timestamp("2016-01-01")),
522+
(0, Timestamp("2016-01-03")),
523+
(1, Timestamp("2016-01-05")),
524+
(1, Timestamp("2016-01-07")),
525+
],
526+
name=("group", "date"),
527+
),
528+
)
529+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)