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

Mean of dataframe with object column returns dataframe of complex128 dtype #22753

Closed
bear24rw opened this Issue Sep 18, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@bear24rw
Copy link

bear24rw commented Sep 18, 2018

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'name': ['a']})
df['value'] = 0.5
print(df.mean(numeric_only=True))
print()
print(df.mean())
value    0.5
dtype: float64

name     2.320359906103466e+77j
value                  (0.5+0j)
dtype: complex128

Problem description

Computing the mean of a dataframe that has an object dtype column converts the whole dataframe to a complex type. This is unexpected and different from previous behavior (used to just drop the object columns)

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas: 0.24.0.dev0+608.g1a12c41d2
pytest: None
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.4
numpy: 1.15.1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.6
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.4
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: 1.2.9
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@bear24rw bear24rw changed the title Mean of dataframe with object returns dataframe of complex128 dtype Mean of dataframe with object column returns dataframe of complex128 dtype Sep 18, 2018

@WillAyd

This comment has been minimized.

Copy link
Member

WillAyd commented Sep 19, 2018

Thanks for the report. I was only able to reproduce this on Python 3.7 as earlier versions looked fine. Investigation and PRs would certainly be welcome

@bear24rw

This comment has been minimized.

Copy link

bear24rw commented Sep 19, 2018

I can repo on Ubuntu 18.04

$ python3.6 test2.py
1.16.0.dev0+7fcba41
0.24.0.dev0+614.g40dfadd02
value    0.5
dtype: float64

value    0.5
dtype: float64
$ python3.7 test2.py
1.16.0.dev0+7fcba41
0.24.0.dev0+614.g40dfadd02
value    0.5
dtype: float64

name     (4.67892852249246e-310+6.909430494962e-310j)
value                                        (0.5+0j)
dtype: complex128

@bear24rw

This comment has been minimized.

Copy link

bear24rw commented Sep 19, 2018

I opened numpy/numpy#11993 which I believe might be the root of this issue.

@bear24rw

This comment has been minimized.

Copy link

bear24rw commented Oct 1, 2018

Fixed via numpy/numpy#11993

@bear24rw bear24rw closed this Oct 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment