Skip to content

Commit 156c83d

Browse files
phoflmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#46325: Regression in read csv causing segfault for invalid file input
1 parent 92d7992 commit 156c83d

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
@@ -1227,6 +1227,10 @@ def _make_engine(
12271227
assert self.handles is not None
12281228
f = self.handles.handle
12291229

1230+
elif engine != "python":
1231+
msg = f"Invalid file path or buffer object type: {type(f)}"
1232+
raise ValueError(msg)
1233+
12301234
try:
12311235
return mapping[engine](f, **self.options)
12321236
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_invalide_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)