-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: String upgraded to complex128 (and cascading to other columns) in df.mean() and df.agg('mean') #36703
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
Comments
Thanks for the report, PRs to fix are welcome! |
I just updated the code examples with more exploration of where this actually happens. It's in Lines 1409 to 1435 in 2a7d332
If something passed in is an object dtype, it tries to convert it to It's not exactly clear to me where the best place to fix it would be. The logic for some of the other functions works differently (often making sure that something can be cast to a float). The standard library I think the problem is that this behavior is implicit, and I wonder if using complex numbers is a common enough use case to get implicit casting of strings without a warning (cf. the one for datetime means). The use here along with Thoughts on where/how to fix it? |
take |
@biddwan09 I poked around a bit more, and here are a couple of thoughts:
I hope that helps! |
@jtkiley thanks for the approaches. I will try to understand how the sum method works and put a fix from there |
I had a similar issue running M1 on Macos 12.4
The issue was resolved when I installed I'd like feedback if someone seeing the same issue managed to workaround it the same way. |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas (1.1.1; latest from conda).
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
With output:
Problem description
It seems like
df.mean()
is being too aggressive about attempting to work with string columns in a one-row dataframe. In my use case, if I get a query result with one row, I get this bug. I have lots of these queries, and even one of them being affected will flow through to the concatenated dataframe downstream.I first noticed this by getting an error that I couldn't write a parquet file with a complex128 column, and tracked it back from there.
Expected Output
Expected output is what we get with
numeric_only=True
set or more than one row. See above.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2ca0a2
python : 3.8.5.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.6.0.post20200814
Cython : None
pytest : 6.0.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.19
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: