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

Issue with DataFrame.rename and the columns named argument #71

Closed
gerardsyd opened this issue Jul 8, 2020 · 7 comments
Closed

Issue with DataFrame.rename and the columns named argument #71

gerardsyd opened this issue Jul 8, 2020 · 7 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@gerardsyd
Copy link

Environment data

  • Language Server version: 2020.6.1
  • OS and version: Windows 10.1903
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.7
  • Pandas version: 1.0.5

Expected behaviour

When using df.rename() and passing columns as a named argument, no error is raised as this is per the documentation:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html

Actual behaviour

Pylance shows an error saying no parameter named "columns". I've recreated the issue in the code below. It seems to have something to do with using groupby which leads Pylance to believe the DataFrame is a Series object

image

Code Snippet / Additional information

import pandas as pd


df = pd.DataFrame({'col1': ['a', 'b', 'b', 'd'], 'Data': [1, 2, 3, 4]})
print(df)
df = df.groupby('col1').last().reset_index()
print(df)

df.rename(columns={'Data': 'Test'}, inplace=True)
print(df)
@erictraut
Copy link
Contributor

Thanks for the bug report.

@gramster, this looks like a bug in the pandas type stub?

As for the error, I've changed the diagnostics related to argument/parameter matching to be suppressed when type checking mode is disabled. This change will be in the next version of Pylance.

@gramster
Copy link
Member

gramster commented Jul 8, 2020 via email

@tamuhey
Copy link

tamuhey commented Jul 8, 2020

Pylance also infer the below code incorrectly:

import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3]})
print(df.fillna("")) # Error: No overloads for "df.fillna("")" match parameters

@jakebailey jakebailey added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Jul 8, 2020
@CatNofishing
Copy link

Some functions have no intelligent suggestions in Pandas. For example :

import pandas as pd
frame=pd.DataFrame()

image

@erictraut
Copy link
Contributor

@gramster, this looks like a bug in the pandas type stub. The __init__.pyi stub is importing DataFrame, but it's not re-exporting it in the top-level namespace for the pandas module.

To re-export a symbol from a type stub, you need to use the "as" syntax (as per PEP 484). Something like this...

from .core import DataFrame as DataFrame

@jakebailey
Copy link
Member

jakebailey commented Jul 9, 2020

That's #13 (but not fixed).

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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