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

GroupBy handles non-numeric data differently for different aggregation functions #20871

Closed
Dominik1123 opened this issue Apr 29, 2018 · 1 comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Groupby

Comments

@Dominik1123
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd

s = pd.Series(
    [1, 2, 3, 4],
    index=['a', 'a', 'b', 'b'],
    dtype=object
)
print(s.groupby(lambda x: x).sum())  # Works fine.
print(s.groupby(lambda x: x).mean())  # Raises `DataError`.

Problem description

GroupBy objects behave differently for different aggregation functions when used on non-numeric data types. mean (amongst others) re-raises on GroupByError while sum (amongst others) falls back on np.sum.

The expected behavior would be that all such functions either fall back on their numpy equivalent or re-raise on DataError for non-numeric data.

Expected Output

All such functions should either fall back on their numpy equivalent or re-raise on DataError for non-numeric data.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-119-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 34.2.0
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 5.2.2
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.1
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback jreback added Groupby Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request labels Apr 29, 2018
@jreback jreback added this to the No action milestone Apr 29, 2018
@jreback
Copy link
Contributor

jreback commented Apr 29, 2018

duplicates of #13416 and slightly to #13992

@jreback jreback closed this as completed Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Groupby
Projects
None yet
Development

No branches or pull requests

2 participants