Skip to content

TST: Add regression test for empty DataFrame groupby #18097

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

Conversation

Licht-T
Copy link
Contributor

@Licht-T Licht-T commented Nov 3, 2017

@gfyoung gfyoung added Groupby Testing pandas testing functions or related to the test suite labels Nov 3, 2017
def test_empty_dataframe_groupby(self):
# GH8093
df = pd.DataFrame(columns=['A', 'B', 'C'])
assert df.groupby('A').sum().index.name == 'A'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well also check that the DataFrame that we get as a result is correct.

@Licht-T Licht-T force-pushed the add-regression-test-for-empty-dataframe-groupby branch from 03e2e17 to e5244a0 Compare November 3, 2017 20:00
@Licht-T
Copy link
Contributor Author

Licht-T commented Nov 3, 2017

Thanks @gfyoung, fixed!

@codecov
Copy link

codecov bot commented Nov 3, 2017

Codecov Report

Merging #18097 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18097      +/-   ##
==========================================
- Coverage   91.25%   91.23%   -0.02%     
==========================================
  Files         163      163              
  Lines       50120    50120              
==========================================
- Hits        45737    45728       -9     
- Misses       4383     4392       +9
Flag Coverage Δ
#multiple 89.04% <ø> (ø) ⬆️
#single 40.32% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27bbea7...e5244a0. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 3, 2017

Codecov Report

Merging #18097 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18097      +/-   ##
==========================================
- Coverage   91.25%   91.23%   -0.02%     
==========================================
  Files         163      163              
  Lines       50120    50120              
==========================================
- Hits        45737    45728       -9     
- Misses       4383     4392       +9
Flag Coverage Δ
#multiple 89.04% <ø> (ø) ⬆️
#single 40.32% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27bbea7...0b466e6. Read the comment docs.


result = df.groupby('A').sum()
expected = pd.DataFrame(columns=['B', 'C'], dtype=np.float64)
expected.index.rename('A', inplace=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally discourage use of inplace. Just use expected.index.name = 'A'.

df = pd.DataFrame(columns=['A', 'B', 'C'])

result = df.groupby('A').sum()
expected = pd.DataFrame(columns=['B', 'C'], dtype=np.float64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataFrame is already imported, so can remove the pd. to make things a little cleaner

@Licht-T Licht-T force-pushed the add-regression-test-for-empty-dataframe-groupby branch from e5244a0 to 50e538e Compare November 3, 2017 20:16
@Licht-T Licht-T force-pushed the add-regression-test-for-empty-dataframe-groupby branch from 50e538e to 0b466e6 Compare November 3, 2017 20:18
@Licht-T
Copy link
Contributor Author

Licht-T commented Nov 3, 2017

@gfyoung @jschendel Thanks! Fixed!

@jreback jreback added this to the 0.22.0 milestone Nov 4, 2017
@jreback jreback merged commit 52e186c into pandas-dev:master Nov 4, 2017
@jreback
Copy link
Contributor

jreback commented Nov 4, 2017

thanks!

1kastner pushed a commit to 1kastner/pandas that referenced this pull request Nov 5, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Group-by on an empty data object dtype loses the index name (cython aggregation is ok)
4 participants