BUG: SpooledTemporaryFile no longer working with read_csv · Issue #43439 · pandas-dev/pandas (original) (raw)

Reproducible Example

import os import pandas import tempfile import traceback

with tempfile.SpooledTemporaryFile() as f: f.write(b'abcd') f.seek(0)

try:
    result = pandas.read_csv(f)
    print(result)

except Exception as e:
    print(e)
    print(traceback.format_exc())

Issue Description

This worked in pandas 1.1.5 but is no longer working in version >=1.2.0.

Expected Behavior

According to the read_csv description I would expect this to work.

filepath_or_bufferstr, path object or file-like object

Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, gs, and file. For file URLs, a host is expected. A local file could be: file://localhost/path/to/table.csv.
If you want to pass in a path object, pandas accepts any os.PathLike.
By file-like object, we refer to objects with a read() method, such as a file handle (e.g. via builtin open function) or StringIO.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 5f648bfpython : 3.7.9.final.0 python-bits : 64 OS : Darwin OS-release : 20.5.0 Version : Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : en_US.UTF-8 LANG : None LOCALE : en_US.UTF-8

pandas : 1.3.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.1.1
setuptools : 47.1.0
IPython : 7.27.0