Skip to content

TST: Add tests for single group #13561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,8 @@ def test_groupby_head_tail(self):
assert_frame_equal(df.loc[[0, 2]], g_not_as.head(1))
assert_frame_equal(df.loc[[1, 2]], g_not_as.tail(1))

empty_not_as = DataFrame(columns=df.columns, index=pd.Index(
[], dtype=df.index.dtype))
empty_not_as = DataFrame(columns=df.columns,
index=pd.Index([], dtype=df.index.dtype))
empty_not_as['A'] = empty_not_as['A'].astype(df.A.dtype)
empty_not_as['B'] = empty_not_as['B'].astype(df.B.dtype)
assert_frame_equal(empty_not_as, g_not_as.head(0))
Expand Down Expand Up @@ -4549,6 +4549,15 @@ def test_groupby_with_empty(self):
grouped = series.groupby(grouper)
assert next(iter(grouped), None) is None

def test_groupby_with_single_column(self):
df = pd.DataFrame({'a': list('abssbab')})
tm.assert_frame_equal(df.groupby('a').get_group('a'), df.iloc[[0, 5]])
# GH 13530
exp = pd.DataFrame([], index=pd.Index(['a', 'b', 's'], name='a'))
tm.assert_frame_equal(df.groupby('a').count(), exp)
tm.assert_frame_equal(df.groupby('a').sum(), exp)
tm.assert_frame_equal(df.groupby('a').nth(1), exp)

def test_groupby_with_small_elem(self):
# GH 8542
# length=2
Expand Down Expand Up @@ -4989,8 +4998,8 @@ def test_cumcount_empty(self):
ge = DataFrame().groupby(level=0)
se = Series().groupby(level=0)

e = Series(dtype='int64'
) # edge case, as this is usually considered float
# edge case, as this is usually considered float
e = Series(dtype='int64')

assert_series_equal(e, ge.cumcount())
assert_series_equal(e, se.cumcount())
Expand Down