Skip to content

Commit b68b604

Browse files
authored
REGR: Check for float in isnaobj_old (#35510)
1 parent 5413b6b commit b68b604

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/source/whatsnew/v1.1.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ including other versions of pandas.
1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717

18-
-
18+
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`).
1919
-
2020
-
2121

pandas/_libs/missing.pyx

+4-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def isnaobj_old(arr: ndarray) -> ndarray:
155155
result = np.zeros(n, dtype=np.uint8)
156156
for i in range(n):
157157
val = arr[i]
158-
result[i] = checknull(val) or val == INF or val == NEGINF
158+
result[i] = (
159+
checknull(val)
160+
or util.is_float_object(val) and (val == INF or val == NEGINF)
161+
)
159162
return result.view(np.bool_)
160163

161164

pandas/tests/io/parser/test_common.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pandas.errors import DtypeWarning, EmptyDataError, ParserError
1919
import pandas.util._test_decorators as td
2020

21-
from pandas import DataFrame, Index, MultiIndex, Series, compat, concat
21+
from pandas import DataFrame, Index, MultiIndex, Series, compat, concat, option_context
2222
import pandas._testing as tm
2323

2424
from pandas.io.parsers import CParserWrapper, TextFileReader, TextParser
@@ -2179,3 +2179,13 @@ def test_read_csv_names_not_accepting_sets(all_parsers):
21792179
parser = all_parsers
21802180
with pytest.raises(ValueError, match="Names should be an ordered collection."):
21812181
parser.read_csv(StringIO(data), names=set("QAZ"))
2182+
2183+
2184+
def test_read_csv_with_use_inf_as_na(all_parsers):
2185+
# https://github.com/pandas-dev/pandas/issues/35493
2186+
parser = all_parsers
2187+
data = "1.0\nNaN\n3.0"
2188+
with option_context("use_inf_as_na", True):
2189+
result = parser.read_csv(StringIO(data), header=None)
2190+
expected = DataFrame([1.0, np.nan, 3.0])
2191+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)