-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Cannot convert from object
numeric strings to Float64Dtype
#40729
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
@tamargrey Thanks for the clear report! Indeed, currently we seem to specifically error when trying to construct a Float64Dtype array from numeric strings. The same is true for Int64Dtype, and also when constructing directly (not through astype):
The underlying reason comes from: pandas/pandas/core/arrays/floating.py Lines 137 to 149 in 5c64037
where we simply disallow this. Contributions always welcome! A possible workaround for now is to first convert to String dtype, and then the conversion to Float64 works:
|
This works now, may need tests |
take |
* TST: Wrote test for Float64 conversion #40729 * TST: Moved test #40729 Co-authored-by: Steven Rotondo <[email protected]>
…8205) * TST: Wrote test for Float64 conversion pandas-dev#40729 * TST: Moved test pandas-dev#40729 Co-authored-by: Steven Rotondo <[email protected]>
Code Sample, a copy-pastable example
the above produces a
TypeError: object cannot be converted to a FloatingDtype
:Problem description
With
float64
, this conversion works, and as the series' dtype would get inferred asobject
even if no dtype was specified, it is unexpected to me that we would not be able to convert to theFloat64Dtype
from that.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.8.2.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/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.2.3
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 41.2.0
Cython : None
pytest : 6.0.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.7
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: