Skip to content

.groupby by should indicate it aligns the passed in Series #15338

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

Closed
kernc opened this issue Feb 7, 2017 · 3 comments
Closed

.groupby by should indicate it aligns the passed in Series #15338

kernc opened this issue Feb 7, 2017 · 3 comments
Labels
Docs Duplicate Report Duplicate issue or pull request Groupby
Milestone

Comments

@kernc
Copy link
Contributor

kernc commented Feb 7, 2017

Code Sample, a copy-pastable example if possible

>>> series = pd.Series([1, 2, 3], index=range(3))

>>> key = pd.Series([0, 0, 1], index=range(3, 6))  # Note: disjunct index

>>> series.groupby(key).sum()
Series([], dtype: int64)

>>> series.groupby(key.values).sum()
0    3
1    3
dtype: int64

Problem description

The current behavior is a bug because the .groupby() documentation says about by parameter:

If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups

Above example shows this not being the case.

Expected Output

With above setup:

>>> series.groupby(key).sum()
0    3
1    3
dtype: int64

Output of pd.show_versions()

pandas: 0.19.0+416.ge1390cd
@kernc
Copy link
Contributor Author

kernc commented Feb 7, 2017

Might be related to #15244.

I followed to problem to reindexing of the grouper Series which results in the new grouper containing all NaNs.

@jreback
Copy link
Contributor

jreback commented Feb 8, 2017

this is correct, if you pass a Series if will first .align it. So that's why you get an empty result set.
This is not a bug, though I suppose could be better documented.

This was brought up here: #15244

@jreback jreback added this to the 0.20.0 milestone Feb 10, 2017
@jreback jreback changed the title .groupby on Series with disjunct index results in empty groups .groupby by should indicate it aligns the passed in Series Feb 10, 2017
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Mar 23, 2017
@jreback
Copy link
Contributor

jreback commented Mar 23, 2017

closing as dupe of #15244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Duplicate Report Duplicate issue or pull request Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants