Skip to content

Commit 5f94b76

Browse files
steliospetrakis02Yi Wei
authored and
Yi Wei
committed
Add test for groupby with TimeGrouper (pandas-dev#53173)
1 parent af99ffd commit 5f94b76

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/groupby/test_groupby.py

+24
Original file line numberDiff line numberDiff line change
@@ -3058,3 +3058,27 @@ def test_groupby_selection_other_methods(df):
30583058
tm.assert_frame_equal(
30593059
g.filter(lambda x: len(x) == 3), g_exp.filter(lambda x: len(x) == 3)
30603060
)
3061+
3062+
3063+
def test_groupby_with_Time_Grouper():
3064+
idx2 = [
3065+
to_datetime("2016-08-31 22:08:12.000"),
3066+
to_datetime("2016-08-31 22:09:12.200"),
3067+
to_datetime("2016-08-31 22:20:12.400"),
3068+
]
3069+
3070+
test_data = DataFrame(
3071+
{"quant": [1.0, 1.0, 3.0], "quant2": [1.0, 1.0, 3.0], "time2": idx2}
3072+
)
3073+
3074+
expected_output = DataFrame(
3075+
{
3076+
"time2": date_range("2016-08-31 22:08:00", periods=13, freq="1T"),
3077+
"quant": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
3078+
"quant2": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
3079+
}
3080+
)
3081+
3082+
df = test_data.groupby(Grouper(key="time2", freq="1T")).count().reset_index()
3083+
3084+
tm.assert_frame_equal(df, expected_output)

0 commit comments

Comments
 (0)