diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 2e432a768af9e..7bda7c575d994 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -3058,3 +3058,27 @@ def test_groupby_selection_other_methods(df): tm.assert_frame_equal( g.filter(lambda x: len(x) == 3), g_exp.filter(lambda x: len(x) == 3) ) + + +def test_groupby_with_Time_Grouper(): + idx2 = [ + to_datetime("2016-08-31 22:08:12.000"), + to_datetime("2016-08-31 22:09:12.200"), + to_datetime("2016-08-31 22:20:12.400"), + ] + + test_data = DataFrame( + {"quant": [1.0, 1.0, 3.0], "quant2": [1.0, 1.0, 3.0], "time2": idx2} + ) + + expected_output = DataFrame( + { + "time2": date_range("2016-08-31 22:08:00", periods=13, freq="1T"), + "quant": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + "quant2": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + } + ) + + df = test_data.groupby(Grouper(key="time2", freq="1T")).count().reset_index() + + tm.assert_frame_equal(df, expected_output)