Skip to content

Commit 95bc7d1

Browse files
discortjreback
authored andcommitted
added test for resampler in a list grouper with NaT (#22470)
1 parent d2b847f commit 95bc7d1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/test_grouping.py

+17
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,23 @@ def test_grouping_labels(self, mframe):
534534
exp_labels = np.array([2, 2, 2, 0, 0, 1, 1, 3, 3, 3], dtype=np.intp)
535535
assert_almost_equal(grouped.grouper.labels[0], exp_labels)
536536

537+
def test_list_grouper_with_nat(self):
538+
# GH 14715
539+
df = pd.DataFrame({'date': pd.date_range('1/1/2011',
540+
periods=365, freq='D')})
541+
df.iloc[-1] = pd.NaT
542+
grouper = pd.Grouper(key='date', freq='AS')
543+
544+
# Grouper in a list grouping
545+
result = df.groupby([grouper])
546+
expected = {pd.Timestamp('2011-01-01'): pd.Index(list(range(364)))}
547+
tm.assert_dict_equal(result.groups, expected)
548+
549+
# Test case without a list
550+
result = df.groupby(grouper)
551+
expected = {pd.Timestamp('2011-01-01'): 365}
552+
tm.assert_dict_equal(result.groups, expected)
553+
537554

538555
# get_group
539556
# --------------------------------

0 commit comments

Comments
 (0)