From 7c02964b838f4504ad98420945c027c983f4e984 Mon Sep 17 00:00:00 2001 From: Ashar Date: Fri, 28 Feb 2025 15:31:41 -0500 Subject: [PATCH] TST: Add test for groupby with datetime and NaT values --- pandas/tests/groupby/test_groupby.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index e08ddf750b00c..4b1f23c1f755e 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2978,3 +2978,21 @@ def test_groupby_multi_index_codes(): index = df_grouped.index tm.assert_index_equal(index, MultiIndex.from_frame(index.to_frame())) + + +def test_groupby_datetime_with_nat(): + # GH##35202 + df = DataFrame( + { + "a": [ + to_datetime("2019-02-12"), + to_datetime("2019-02-12"), + to_datetime("2019-02-13"), + pd.NaT, + ], + "b": [1, 2, 3, 4], + } + ) + grouped = df.groupby("a", dropna=False) + result = len(grouped) + assert result == 3