diff --git a/doc/source/whatsnew/v1.4.2.rst b/doc/source/whatsnew/v1.4.2.rst index badda6a73d1c8..239f02b0b6bcf 100644 --- a/doc/source/whatsnew/v1.4.2.rst +++ b/doc/source/whatsnew/v1.4.2.rst @@ -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`) - diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 7684fa32fbd66..95b03c9844219 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -1710,6 +1710,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: diff --git a/pandas/tests/io/parser/test_unsupported.py b/pandas/tests/io/parser/test_unsupported.py index 7937f47e8bff5..f346fad7acecf 100644 --- a/pandas/tests/io/parser/test_unsupported.py +++ b/pandas/tests/io/parser/test_unsupported.py @@ -189,3 +189,13 @@ def test_close_file_handle_on_invalid_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([])