-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: ValueError: 1.0 and 0.0 cannot be cast to bool when using pd.read_csv() #34859
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
I think this just hasn't been implemented yet. Converting floats came up when BooleanArray was added, but IIRC we kept things simple at first. To fix, we'll want to update |
Is this intended/desired to accept |
Hey @TomAugspurger and @jorisvandenbossche , do you think I should create a PR to enhance the |
This was discussed a bit in the original issue / PR implementing boolean array. You might want to read through it to get some context. But IIRC the decision to not accept them at first was just for simplifying the initial implementation. I think we'd be find accepting them now. |
Yes, I think at least 0's and 1's should be fine to accept (other numbers might require some extra discussion) |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample
Problem description
I would expect that 1.0, 0.0 and None can be cast to a nullable boolean. Using
pd.read_csv()
without dtype assignment assigns float64 dtype. Why does "boolean" not work?Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.None
pandas : 1.0.4
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.3.0.post20200616
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.15.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: