Skip to content

Commit 9accef8

Browse files
mroeschkejreback
authored andcommitted
TST: Groupby.groups of datetimeindex (#11442) (#14952)
add get_group test
1 parent 5710947 commit 9accef8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/groupby/test_groupby.py

+21
Original file line numberDiff line numberDiff line change
@@ -3933,6 +3933,27 @@ def test_groupby_groups_datetimeindex(self):
39333933
groups = grouped.groups
39343934
tm.assertIsInstance(list(groups.keys())[0], datetime)
39353935

3936+
# GH 11442
3937+
index = pd.date_range('2015/01/01', periods=5, name='date')
3938+
df = pd.DataFrame({'A': [5, 6, 7, 8, 9],
3939+
'B': [1, 2, 3, 4, 5]}, index=index)
3940+
result = df.groupby(level='date').groups
3941+
dates = ['2015-01-05', '2015-01-04', '2015-01-03',
3942+
'2015-01-02', '2015-01-01']
3943+
expected = {pd.Timestamp(date): pd.DatetimeIndex([date], name='date')
3944+
for date in dates}
3945+
tm.assert_dict_equal(result, expected)
3946+
3947+
grouped = df.groupby(level='date')
3948+
for date in dates:
3949+
result = grouped.get_group(date)
3950+
data = [[df.loc[date, 'A'], df.loc[date, 'B']]]
3951+
expected_index = pd.DatetimeIndex([date], name='date')
3952+
expected = pd.DataFrame(data,
3953+
columns=list('AB'),
3954+
index=expected_index)
3955+
tm.assert_frame_equal(result, expected)
3956+
39363957
def test_groupby_groups_datetimeindex_tz(self):
39373958
# GH 3950
39383959
dates = ['2011-07-19 07:00:00', '2011-07-19 08:00:00',

0 commit comments

Comments
 (0)