Skip to content

Commit c09a9e1

Browse files
phoflyehoshuadimarsky
authored andcommitted
Regression in read csv causing segfault for invalid file input (pandas-dev#46325)
1 parent 027faf0 commit c09a9e1

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/source/whatsnew/v1.4.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ including other versions of pandas.
1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717
- Fixed regression in :meth:`DataFrame.drop` and :meth:`Series.drop` when :class:`Index` had extension dtype and duplicates (:issue:`45860`)
18+
- Fixed regression in :func:`read_csv` killing python process when invalid file input was given for ``engine="c"`` (:issue:`45957`)
1819
- Fixed memory performance regression in :meth:`Series.fillna` when called on a :class:`DataFrame` column with ``inplace=True`` (:issue:`46149`)
1920
- Provided an alternative solution for passing custom Excel formats in :meth:`.Styler.to_excel`, which was a regression based on stricter CSS validation. Examples available in the documentation for :meth:`.Styler.format` (:issue:`46152`)
2021
-

pandas/io/parsers/readers.py

+4
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,10 @@ def _make_engine(
17101710
assert self.handles is not None
17111711
f = self.handles.handle
17121712

1713+
elif engine != "python":
1714+
msg = f"Invalid file path or buffer object type: {type(f)}"
1715+
raise ValueError(msg)
1716+
17131717
try:
17141718
return mapping[engine](f, **self.options)
17151719
except Exception:

pandas/tests/io/parser/test_unsupported.py

+10
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,13 @@ def test_close_file_handle_on_invalid_usecols(all_parsers):
189189
parser.read_csv(fname, usecols=["col1", "col2", "col3"])
190190
# unlink fails on windows if file handles still point to it
191191
os.unlink(fname)
192+
193+
194+
def test_invalid_file_inputs(all_parsers):
195+
# GH#45957
196+
parser = all_parsers
197+
if parser.engine == "python":
198+
pytest.skip("Python engine supports lists.")
199+
200+
with pytest.raises(ValueError, match="Invalid"):
201+
parser.read_csv([])

0 commit comments

Comments
 (0)