Skip to content

Pandas stub fixes #129

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 7 commits into from
Jan 31, 2022
Merged

Pandas stub fixes #129

merged 7 commits into from
Jan 31, 2022

Conversation

gramster
Copy link
Member

Add a few missing files.
Update .gitignore.
Make some fixes based on the tests from the pandas-stubs package (more to come).

gramster and others added 5 commits January 21, 2022 18:17
Update .gitignore.
Make some fixes based on the tests from the pandas-stubs package (more to come).
Accidental checkin
@@ -1332,7 +1333,6 @@ observed : bool, default False

Returns
-------
DataFrameGroupBy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataFrameGroupBy removed on purpose?

@yanyongyu
Copy link

yanyongyu commented Jan 25, 2022

pandas.io.parsers.TextFileReader now support context manager with __enter__ and __exit__ function but not include in stub file

class TextFileReader(abc.Iterator):
f = ...
orig_options = ...
engine = ...
chunksize = ...
nrows = ...
squeeze = ...
def __init__(self, f, engine = ..., **kwds) -> None: ...
def close(self) -> None: ...
def __next__(self): ...
def read(self, nrows = ...): ...
def get_chunk(self, size = ...): ...

Change IO back to FilePathOrBuffer
@gramster gramster merged commit 5231859 into microsoft:main Jan 31, 2022
@gramster gramster deleted the pandas branch January 31, 2022 23:40
@Dr-Irv
Copy link
Contributor

Dr-Irv commented Feb 1, 2022

@gramster this change broke stuff in read_csv that I fixed in a previous PR. See the test here:
#109 (comment)

read_csv() was OK in pylance 2022.1.3, but now broken in pylance 2022.1.5

@gramster
Copy link
Member Author

gramster commented Feb 1, 2022

I don't think it's this change; there was a reversion to IO that happened in the copy in pylance that has since been fixed but must have made it out in the release. This change already includes that reversion.

If you edit your ~/.vscode/extensions/ms-python.vscode-pylance-2022.1.5/dist/bundled/stubs/pandas/io/parsers.pyi file and change the two lines that say:

    reader: IO,

to

    filepath: FilePathOrBuffer,

I think you should be good.

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Feb 1, 2022

@gramster even if I do the change above, then the following test fails:

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)

All the assignments to variables starting with tr should be legal, while the assignments to the ones using ftr should fail.

The deletion of the * argument at the beginning is what I believe to be the cause of those failures.

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.

4 participants