Skip to content

Commit b4b1e96

Browse files
sinhrksjorisvandenbossche
authored andcommitted
TST: Add tests for single group (#13561)
1 parent 4aff800 commit b4b1e96

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pandas/tests/test_groupby.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -2085,8 +2085,8 @@ def test_groupby_head_tail(self):
20852085
assert_frame_equal(df.loc[[0, 2]], g_not_as.head(1))
20862086
assert_frame_equal(df.loc[[1, 2]], g_not_as.tail(1))
20872087

2088-
empty_not_as = DataFrame(columns=df.columns, index=pd.Index(
2089-
[], dtype=df.index.dtype))
2088+
empty_not_as = DataFrame(columns=df.columns,
2089+
index=pd.Index([], dtype=df.index.dtype))
20902090
empty_not_as['A'] = empty_not_as['A'].astype(df.A.dtype)
20912091
empty_not_as['B'] = empty_not_as['B'].astype(df.B.dtype)
20922092
assert_frame_equal(empty_not_as, g_not_as.head(0))
@@ -4549,6 +4549,15 @@ def test_groupby_with_empty(self):
45494549
grouped = series.groupby(grouper)
45504550
assert next(iter(grouped), None) is None
45514551

4552+
def test_groupby_with_single_column(self):
4553+
df = pd.DataFrame({'a': list('abssbab')})
4554+
tm.assert_frame_equal(df.groupby('a').get_group('a'), df.iloc[[0, 5]])
4555+
# GH 13530
4556+
exp = pd.DataFrame([], index=pd.Index(['a', 'b', 's'], name='a'))
4557+
tm.assert_frame_equal(df.groupby('a').count(), exp)
4558+
tm.assert_frame_equal(df.groupby('a').sum(), exp)
4559+
tm.assert_frame_equal(df.groupby('a').nth(1), exp)
4560+
45524561
def test_groupby_with_small_elem(self):
45534562
# GH 8542
45544563
# length=2
@@ -4989,8 +4998,8 @@ def test_cumcount_empty(self):
49894998
ge = DataFrame().groupby(level=0)
49904999
se = Series().groupby(level=0)
49915000

4992-
e = Series(dtype='int64'
4993-
) # edge case, as this is usually considered float
5001+
# edge case, as this is usually considered float
5002+
e = Series(dtype='int64')
49945003

49955004
assert_series_equal(e, ge.cumcount())
49965005
assert_series_equal(e, se.cumcount())

0 commit comments

Comments
 (0)