Skip to content

BUG: Reading files fails when option use_inf_as_na is set to True #35648

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

Closed
1 task
Khris777 opened this issue Aug 10, 2020 · 1 comment
Closed
1 task

BUG: Reading files fails when option use_inf_as_na is set to True #35648

Khris777 opened this issue Aug 10, 2020 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@Khris777
Copy link

Khris777 commented Aug 10, 2020

  • [ x] I have checked that this issue has not already been reported.

  • [ x] 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, a copy-pastable example

import pandas as pd
pd.set_option("use_inf_as_na", True)
pd.read_csv(some_csv_file)

Problem description

When the option use_inf_as_na is set to True reading any csv-file fails with this error:

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\io\parsers.py", line 686, in read_csv
    return _read(filepath_or_buffer, kwds)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\io\parsers.py", line 458, in _read
    data = parser.read(nrows)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\io\parsers.py", line 1201, in read
    df = DataFrame(col_dict, columns=columns, index=index)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\frame.py", line 467, in __init__
    mgr = init_dict(data, index, columns, dtype=dtype)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\internals\construction.py", line 250, in init_dict
    missing = arrays.isna()

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\series.py", line 4795, in isna
    return super().isna()

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\generic.py", line 7109, in isna
    return isna(self).__finalize__(self, method="isna")

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\dtypes\missing.py", line 124, in isna
    return _isna(obj)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\dtypes\missing.py", line 157, in _isna
    return _isna_ndarraylike(obj, inf_as_na=inf_as_na)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\dtypes\missing.py", line 218, in _isna_ndarraylike
    result = _isna_string_dtype(values, dtype, inf_as_na=inf_as_na)

  File "C:\Users\My.Name\AppData\Local\Continuum\miniconda3\envs\main\lib\site-packages\pandas\core\dtypes\missing.py", line 246, in _isna_string_dtype
    vec = libmissing.isnaobj_old(values.ravel())

  File "pandas\_libs\missing.pyx", line 160, in pandas._libs.missing.isnaobj_old

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

EDIT 1: Error also happens with read_table() and when feeding a StringIO object to read_csv().

EDIT 2: read_excel() fails as well.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : None.None

pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 49.2.1.post20200802
Cython : 0.29.21
pytest : None
hypothesis : None
sphinx : 3.1.2
blosc : None
feather : None
xlsxwriter : 1.3.1
lxml.etree : 4.5.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.17.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fsspec : 0.8.0
fastparquet : 0.4.1
gcsfs : None
matplotlib : 3.3.0
numexpr : None
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 1.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : 1.3.18
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : None
numba : 0.50.1

@Khris777 Khris777 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 10, 2020
@Khris777 Khris777 changed the title BUG: read_csv() fails when option use_inf_as_na is set to True BUG: Reading files fails when option use_inf_as_na is set to True Aug 10, 2020
@jorisvandenbossche
Copy link
Member

@Khris777 thanks for the report. This is a duplicate of #35493, and is already fixed in master and will be included in the 1.1.1 release.

@jorisvandenbossche jorisvandenbossche added Duplicate Report Duplicate issue or pull request and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants