diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 8a14765aa6df2..9a4d39b4e3390 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -493,6 +493,7 @@ Bug Fixes - Bug in ``pd.read_csv()`` in which the ``nrows`` argument was not properly validated for both engines (:issue:`10476`) - Bug in ``pd.read_csv()`` with ``engine='python'`` in which infinities of mixed-case forms were not being interpreted properly (:issue:`13274`) - Bug in ``pd.read_csv()`` with ``engine='python'`` in which trailing ``NaN`` values were not being parsed (:issue:`13320`) +- Bug in ``pd.read_csv()`` with ``engine='python'`` when reading from a tempfile.TemporaryFile on Windows with Python 3, separator expressed as a regex (:issue:`13398`) - Bug in ``pd.read_csv()`` that prevents ``usecols`` kwarg from accepting single-byte unicode strings (:issue:`13219`) - Bug in ``pd.read_csv()`` that prevents ``usecols`` from being an empty set (:issue:`13402`) - Bug in ``pd.read_csv()`` with ``engine=='c'`` in which null ``quotechar`` was not accepted even though ``quoting`` was specified as ``None`` (:issue:`13411`) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 9baff67845dac..dc9455289b757 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -1868,7 +1868,7 @@ class MyDialect(csv.Dialect): else: def _read(): - line = next(f) + line = f.readline() pat = re.compile(sep) yield pat.split(line.strip()) for line in f: diff --git a/pandas/io/tests/parser/python_parser_only.py b/pandas/io/tests/parser/python_parser_only.py index a08cb36c13f80..6f0ea75c4da93 100644 --- a/pandas/io/tests/parser/python_parser_only.py +++ b/pandas/io/tests/parser/python_parser_only.py @@ -171,3 +171,17 @@ def test_read_table_buglet_4x_multiindex(self): columns=list('abcABC'), index=list('abc')) actual = self.read_table(StringIO(data), sep='\s+') tm.assert_frame_equal(actual, expected) + + def test_temporary_file(self): + # GH13398 + data1 = "0 0" + + from tempfile import TemporaryFile + new_file = TemporaryFile("w+") + new_file.write(data1) + new_file.flush() + new_file.seek(0) + + result = self.read_csv(new_file, sep=r"\s*", header=None) + expected = DataFrame([[0, 0]]) + tm.assert_frame_equal(result, expected)