Skip to content

DataFrame aggregation methods inconsistent when object columns have missing values #16832

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
tdpetrou opened this issue Jul 5, 2017 · 4 comments · Fixed by #29345
Closed
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@tdpetrou
Copy link
Contributor

tdpetrou commented Jul 5, 2017

Code Sample, a copy-pastable example if possible

>>> df = pd.DataFrame({'A':['a', None], 'B':['a', 'b']})
>>> df.min()
Series([], dtype: float64)

>>> df[['B', 'A']].min()
B    a
dtype: object

Problem description

Both DataFrames should return the same thing. Order should not matter here. I suppose this is happening based on whether or not the first column has any missing values?

This happens for the other aggregation methods max and sum

Expected Output

For consistency, both should output the same thing.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.1.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.20.2
pytest: 3.0.7
pip: 9.0.1
setuptools: 35.0.2
Cython: 0.25.2
numpy: 1.13.0
scipy: 0.19.0
xarray: None
IPython: 6.0.0
sphinx: 1.5.5
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: 0.3.0.post

@jreback
Copy link
Contributor

jreback commented Jul 5, 2017

generally doing numeric operations on object dtypes is pretty suspect, though I suppose this should work. If you'd have a look would be great.

@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations Difficulty Intermediate labels Jul 5, 2017
@jreback jreback added this to the Next Major Release milestone Jul 5, 2017
@jondo
Copy link

jondo commented Nov 5, 2018

My workaround:

In: [df[col].dropna().min() for col in df.columns]
Out: ['a', 'a']

(For some reason, this is also much faster on my current data.)

@mroeschke
Copy link
Member

This looks to work on master. Could use a test.

In [63]: >>> df = pd.DataFrame({'A':['a', None], 'B':['a', 'b']})
    ...: >>> df.min()
Out[63]:
B    a
dtype: object

In [64]: df[['B', 'A']].min()
Out[64]:
B    a
dtype: object

In [65]: pd.__version__
Out[65]: '0.26.0.dev0+593.g9d45934af'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Difficulty Intermediate Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations labels Oct 20, 2019
@mjarosie
Copy link
Contributor

mjarosie commented Nov 2, 2019

Hi,

I'd like to pick this issue up. Will fill in a PR soon.

@jreback jreback modified the milestones: Contributions Welcome, 1.0 Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants