Skip to content

Backport PR #46325 on branch 1.4.x (Regression in read csv causing segfault for invalid file input) #46333

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ including other versions of pandas.
Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed regression in :meth:`DataFrame.drop` and :meth:`Series.drop` when :class:`Index` had extension dtype and duplicates (:issue:`45860`)
- Fixed regression in :func:`read_csv` killing python process when invalid file input was given for ``engine="c"`` (:issue:`45957`)
- Fixed memory performance regression in :meth:`Series.fillna` when called on a :class:`DataFrame` column with ``inplace=True`` (:issue:`46149`)
- 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`)
-
Expand Down
4 changes: 4 additions & 0 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@ def _make_engine(
assert self.handles is not None
f = self.handles.handle

elif engine != "python":
msg = f"Invalid file path or buffer object type: {type(f)}"
raise ValueError(msg)

try:
return mapping[engine](f, **self.options)
except Exception:
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,13 @@ def test_close_file_handle_on_invalide_usecols(all_parsers):
parser.read_csv(fname, usecols=["col1", "col2", "col3"])
# unlink fails on windows if file handles still point to it
os.unlink(fname)


def test_invalid_file_inputs(all_parsers):
# GH#45957
parser = all_parsers
if parser.engine == "python":
pytest.skip("Python engine supports lists.")

with pytest.raises(ValueError, match="Invalid"):
parser.read_csv([])