From c362f5fb8424b12ce5360618a1784f70681afdc2 Mon Sep 17 00:00:00 2001 From: TrigonaMinima Date: Thu, 14 Feb 2019 03:35:43 +0530 Subject: [PATCH] 9236: test for the DataFrame.groupby with MultiIndex having pd.NaT --- pandas/tests/groupby/test_groupby.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 1ae8efd2f6867..12a5d494648fc 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -1698,3 +1698,19 @@ def test_groupby_agg_ohlc_non_first(): result = df.groupby(pd.Grouper(freq='D')).agg(['sum', 'ohlc']) tm.assert_frame_equal(result, expected) + + +def test_groupby_multiindex_nat(): + # GH 9236 + values = [ + (pd.NaT, 'a'), + (datetime(2012, 1, 2), 'a'), + (datetime(2012, 1, 2), 'b'), + (datetime(2012, 1, 3), 'a') + ] + mi = pd.MultiIndex.from_tuples(values, names=['date', None]) + ser = pd.Series([3, 2, 2.5, 4], index=mi) + + result = ser.groupby(level=1).mean() + expected = pd.Series([3., 2.5], index=["a", "b"]) + assert_series_equal(result, expected)