Skip to content
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

BUG: failed to aggregate #44119

Closed
2 of 3 tasks
wxinl opened this issue Oct 20, 2021 · 3 comments
Closed
2 of 3 tasks

BUG: failed to aggregate #44119

wxinl opened this issue Oct 20, 2021 · 3 comments
Labels
Apply Apply, Aggregate, Transform, Map Bug Duplicate Report Duplicate issue or pull request Groupby Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).

Comments

@wxinl
Copy link

wxinl commented Oct 20, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
df1 = pd.DataFrame(dict2 = {'index': {0: 7158892,1: 7158893,2: 7158894,3: 7158895,4: 7158896,5: 7158897,6: 7158898},
 'uid': {0: 1081156,1: 1081156,2: 1081156,3: 1081156,4: 1081156,5: 1081156,6: 1081156},
 'lat': {0: 37.524228,1: 37.546708,2: 37.433964,3: 38.245017,4: 37.546708,5: 37.500817,6: 37.433964},
'lng': {0: -121.94779,1: -122.069067,2: -121.886765,3: -121.455548,4: -122.069067,5: -121.981362,6: -121.886765}})

agg1 = df1.groupby(['uid']).agg(pd.Series.mode)

Issue Description

ValueError: could not broadcast input array from shape (7,4) into shape (7,)

Expected Behavior

expect something like this:
1081156,[37.433964 37.546708],[-121.886765 -122.069067]

Installed Versions

INSTALLED VERSIONS ------------------ commit : 945c9ed python : 3.9.7.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-81-generic Version : #91~18.04.1-Ubuntu SMP Fri Jul 23 13:36:29 UTC 2021 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : None
pytest : None
hypothesis : None
show more (open the raw output data in a text editor) ...

tabulate : None
xarray : 0.19.0
xlrd : None
xlwt : None
numba : None

@wxinl wxinl added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 20, 2021
@mzeitlin11
Copy link
Member

Thanks for reporting this @wxinl! Probably the same as #38534?

@mzeitlin11 mzeitlin11 added Apply Apply, Aggregate, Transform, Map Duplicate Report Duplicate issue or pull request Groupby Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 20, 2021
@mzeitlin11
Copy link
Member

Closing in favor of the other issue

@wxinl
Copy link
Author

wxinl commented Oct 21, 2021

Solved by adding a pseudo row at the top of the dataframe to initialize the aggregation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Duplicate Report Duplicate issue or pull request Groupby Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.).
Projects
None yet
Development

No branches or pull requests

2 participants