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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With