Skip to content

fix read_csv to work with different overloads #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Feb 4, 2022

pylance 2022.2.0

The following code reports errors incorrectly:

from io import StringIO
import pandas as pd
from pandas.io.parsers import TextFileReader

dio = StringIO("a,b\n 1,2\n 3,4\n")

df: pd.DataFrame = pd.read_csv(dio)

print(df)

dio.seek(0)
tr: pd.DataFrame = pd.read_csv(dio)

dio.seek(0)
tr2: TextFileReader = pd.read_csv(dio, iterator=True)

dio.seek(0)
tr3: pd.DataFrame = pd.read_csv(dio, iterator=False)

dio.seek(0)
tr5: TextFileReader = pd.read_csv(dio, chunksize=10)

dio.seek(0)
tr6: pd.DataFrame = pd.read_csv(dio, chunksize=None)

dio.seek(0)
tr7: pd.DataFrame = pd.read_csv(dio, header="infer")

dio.seek(0)
tr8: TextFileReader = pd.read_csv(dio, header="infer", iterator=True)


ftr1: TextFileReader = pd.read_csv("hey.csv")
ftr2: pd.DataFrame = pd.read_csv("hey.csv", iterator=True)
ftr3: TextFileReader = pd.read_csv("hey.csv", iterator=False)
ftr5: pd.DataFrame = pd.read_csv("hey.csv", chunksize=10)
ftr6: TextFileReader = pd.read_csv("he.csv", chunksize=None)
ftr7: TextFileReader = pd.read_csv("hey.csv", header="infer")
ftr8: pd.DataFrame = pd.read_csv("hey.csv", header="infer", iterator=True)

e.g., on the first assignment of tr1:

Expression of type "TextFileReader" cannot be assigned to declared type "DataFrame"
  "TextFileReader" is incompatible with "DataFrame"

The test code above is set up to pass on all the assignments to tr# and fail on the assignments to ftr#

This was all working with PR #87 and I think #129 messed it up (@gramster)

@gramster gramster merged commit a9361b6 into microsoft:main Feb 7, 2022
@Dr-Irv Dr-Irv deleted the csvfix branch February 18, 2022 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants