Skip to content
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

Pylance does not show me the docstring for the to_csv() method #550

Closed
karthiknadig opened this issue Nov 2, 2020 · 3 comments
Closed
Labels
docstrings fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@karthiknadig
Copy link
Member

@karthiknadig Thanks, I gave it a try but it does not yet look ready for prime to me. Without going into detail, Pylance does not show me the docstring for the to_csv() method while hovering in the following example whereas the default Python language server can do this:

pd.DataFrame([
        {'file_path': html_task.output().path}
    ]).to_csv(stream))

Feel free to create an issue for this if Pylance should be able to support this. :-)

Originally posted by @LinqLover in microsoft/vscode-python#13013 (comment)

@github-actions github-actions bot added the triage label Nov 2, 2020
@judej judej added typestub Issue relating to our bundled type stubs needs investigation Could be an issue - needs investigation labels Nov 2, 2020
@github-actions github-actions bot removed the triage label Nov 2, 2020
@gramster
Copy link
Member

I don't think this should be a "bundled typestub bug". That should only be the case if the docstring is computed and not statically declared. In this case, the docstring is available; the method is inherited from NDFrame and the docstring is at https://github.com/pandas-dev/pandas/blob/639a9c27964b09724a0ae2acdd0e6a10e49ddd88/pandas/core/generic.py#L3228. Pylance should be finding it. I am removing the label.

@gramster gramster removed the typestub Issue relating to our bundled type stubs label Dec 11, 2020
@jakebailey jakebailey added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Mar 3, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202130-3-march-2021

@niderhoff
Copy link

niderhoff commented Feb 1, 2022

Pylance still regularly thinks it should resolve an NDFrame while it shouldn't.
One example:

a = pd.DataFrame()
b = a.infer_objects()

b is of inferred by pyright as NDFrame. But if you click on "Go to Type Definition", you can see the method should return a FrameOrSeries:

image

The type stubs (right click: "Go to Declaration"), however, will show the method should return a NDFrame:

image

Now I have NDFrames all over my code where the stubs are broken basically. Because pylance will complaint that I cannot use basic dataframe methods because they are not implemented on the NDFrame class and the return type of the item getter __getitem__ is also not correct (it always infers the return type as None).

So I dug a little bit and found it NDFrame is implemented as an abstract class and thus has no return type.
We can see it in the pandas code:

image

I think the stubs are a not correctly generated with these abstract classes Pandas is using? Pyright should not infer abstract classes as return types.

Btw, trying to "cast" the NDFrames manually to a DataFrame or Series doesn't work either:

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

Using pandas 1.3.4 btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstrings fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

6 participants