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: Regression from 1.2.5 to 1.3.x: groupby using sum on DataFrame containing lists fails #43108

Closed
3 tasks done
Dr-Irv opened this issue Aug 19, 2021 · 8 comments · Fixed by #43154
Closed
3 tasks done
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Aug 19, 2021

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

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

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


Code Sample, a copy-pastable example

Version 1.3.2:

>>> df=pd.DataFrame([["M", [1]], ["M", [2]], ["W", [10]], ["W", [20]]], columns=["MW", "v"])
>>> df.groupby("MW").sum()
Empty DataFrame
Columns: []
Index: [M, W]
>>> df.groupby("MW").v.sum()
MW
M      [1, 2]
W    [10, 20]
Name: v, dtype: object

Version 1.2.5:

>>> df=pd.DataFrame([["M", [1]], ["M", [2]], ["W", [10]], ["W", [20]]], columns=["MW", "v"])
>>> df.groupby("MW").sum()
           v
MW
M     [1, 2]
W   [10, 20]
>>> df.groupby("MW").v.sum()
MW
M      [1, 2]
W    [10, 20]
Name: v, dtype: object

Problem description

With 1.2.5 and earlier, if the elements of one of the columns are objects that are lists, then the groupby operation with sum creates the aggregation of the lists. With 1.3.2, it doesn't.

Expected Output

Same as 1.2.5

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3af1a4f
python : 3.8.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.4.0.dev0+475.g3af1a4fa27
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 49.6.0.post20210108
Cython : 0.29.23
pytest : 6.2.4
hypothesis : 6.14.1
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : 1.4.3
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.25.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 2021.05.0
fastparquet : 0.6.3
gcsfs : 2021.05.0
matplotlib : 3.3.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 2.0.0
pyxlsb : None
s3fs : 0.4.2
scipy : 1.7.0
sqlalchemy : 1.4.20
tables : 3.6.1
tabulate : 0.8.9
xarray : 0.18.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.52.0

@Dr-Irv Dr-Irv added Bug Groupby Regression Functionality that used to work in a prior pandas version Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). labels Aug 19, 2021
@simonjayhawkins
Copy link
Member

looks similar to #42395. change in behavior reported for non-numeric column

@kurchi1205
Copy link
Contributor

I am new to OpenSource Projects . Can I work on this issue?

@jbrockmendel
Copy link
Member

The default for DataFrameGroupBy.sum's numeric_only is True according to the docstring (in the code it is lib.no_default for code-sharing). Failing to exclude non-numeric columns was a bug pre-1.3

@kurchi1205
Copy link
Contributor

Yeah I got that , I am working on the case when the dataframe has no numeric feature , but by default numeric_only is set to True like in the above one .

@Dr-Irv
Copy link
Contributor Author

Dr-Irv commented Aug 23, 2021

The default for DataFrameGroupBy.sum's numeric_only is True according to the docstring (in the code it is lib.no_default for code-sharing). Failing to exclude non-numeric columns was a bug pre-1.3

Yes, but based on the comment here: #42395 (comment) it seems that we might want to consider changing the default to have numeric_only=False .

@simonjayhawkins
Copy link
Member

Yes, but based on the comment here: #42395 (comment) it seems that we might want to consider changing the default to have numeric_only=False .

closing this to keep discussion in on place.

@Priyanshi-Chauhan
Copy link

Can I work on this issue. Perhaps come up with the contribute to code

@simonjayhawkins
Copy link
Member

Thanks @Priyanshi-Chauhan. This issue is closed. Discussion on this issue now in #42395. There is an open PR to fix #43154.

There are many other issues that could be worked on. I'd recommend any from https://github.com/pandas-dev/pandas/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+label%3A%22Needs+Tests%22

@simonjayhawkins simonjayhawkins added this to the 1.3.3 milestone Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants