Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Inspection Warning with pandas.read_csv read from string buffer

Tags:

pandas

pycharm

My Python environment uses Pandas 1.4.2. I have the following code that reads from a string buffer:

response: requests.Response = session.get(url="...")
data: pandas.DataFrame = pandas.read_csv(io.StringIO(response.content.decode("utf-8")), skiprows=2)

When I run Code Inspection in PyCharm, I get the following warning:

Expected type 'str | PathLike[str] | ReadCsvBuffer[bytes] | ReadCsvBuffer[str]', got 'StringIO' instead

What change should I make to my code to resolve the issue short of suppressing the warning?

like image 740
scorpio Avatar asked Sep 15 '25 13:09

scorpio


1 Answers

I would ignore this warning.

StringIO is meant to be accepted as a valid data type for the read_csv method ("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." - https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html) The issue is with Pandas' own type validation (https://github.com/pandas-dev/pandas/blob/v1.4.2/pandas/io/parsers/readers.py#L584-L680) or PyCharm's handling of it.

like image 66
FinanceGardener Avatar answered Sep 18 '25 11:09

FinanceGardener