Skip to content

Commit 645cf1f

Browse files
committed
Improve coverage with multi and missing column groupby-resample tests.
1 parent cdbe28d commit 645cf1f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

pandas/tests/resample/test_resampler_grouper.py

+49
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,52 @@ def test_groupby_resample_on_index_with_list_of_keys():
566566
),
567567
)
568568
tm.assert_frame_equal(result, expected)
569+
570+
571+
def test_groupby_resample_on_index_with_list_of_keys_multi_columns():
572+
# GH 50876
573+
df = DataFrame(
574+
data={
575+
"group": [0, 0, 0, 0, 1, 1, 1, 1],
576+
"first_val": [3, 1, 4, 1, 5, 9, 2, 6],
577+
"second_val": [2, 7, 1, 8, 2, 8, 1, 8],
578+
"third_val": [1, 4, 1, 4, 2, 1, 3, 5],
579+
},
580+
index=Series(
581+
date_range(start="2016-01-01", periods=8),
582+
name="date",
583+
),
584+
)
585+
result = df.groupby("group").resample("2D")[["first_val", "second_val"]].mean()
586+
expected = DataFrame(
587+
data={
588+
"first_val": [2.0, 2.5, 7.0, 4.0],
589+
"second_val": [4.5, 4.5, 5.0, 4.5],
590+
},
591+
index=Index(
592+
data=[
593+
(0, Timestamp("2016-01-01")),
594+
(0, Timestamp("2016-01-03")),
595+
(1, Timestamp("2016-01-05")),
596+
(1, Timestamp("2016-01-07")),
597+
],
598+
name=("group", "date"),
599+
),
600+
)
601+
tm.assert_frame_equal(result, expected)
602+
603+
604+
def test_groupby_resample_on_index_with_list_of_keys_missing_column():
605+
# GH 50876
606+
df = DataFrame(
607+
data={
608+
"group": [0, 0, 0, 0, 1, 1, 1, 1],
609+
"val": [3, 1, 4, 1, 5, 9, 2, 6],
610+
},
611+
index=Series(
612+
date_range(start="2016-01-01", periods=8),
613+
name="date",
614+
),
615+
)
616+
with pytest.raises(KeyError, match="Columns not found"):
617+
df.groupby("group").resample("2D")[["val_not_in_dataframe"]].mean()

0 commit comments

Comments
 (0)