Skip to content

BUG: SpooledTemporaryFile no longer working with read_csv #43439

Closed
@oskli

Description

@oskli

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

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 : 5f648bf python : 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO CSVread_csv, to_csvRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions