-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_dict() unexpectedly casts np.float32 to python float #50125
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
This demonstrates that the problem is somewhere in
We can go one level below and find the problem on
Ruling out numpy as a suspect:
|
Clearly the problem is that
That said, I don't understand where this casting happens.
So, what is called by This really bugs me!
|
Yes, found it!
To summarise:
Is it really intended that |
Closing the issues based on the following conclusions:
Thus, this problem is hardly avoidable, except if we add an argument to |
EDIT: After more investigation, I found out the root cause of the issue described below: #50125 (comment)
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The reproducible example returns:
We can see that
.round(3)
has been properly carried through.to_records()
but not through.to_dict()
.to_dict()
does not return the original data either, but something like the rounding result with extra decimals.This does not happens if we use
np.float64
.(Similar to issue #35124)
Expected Behavior
Result when using
np.float64
:Installed Versions
INSTALLED VERSIONS
commit : 8dab54d
python : 3.10.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.1
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : 3.6.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : 2022.7
The text was updated successfully, but these errors were encountered: