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

Series.keys() should return an Index and not a list #1101

Open
ClementPinard opened this issue Jan 21, 2025 · 1 comment
Open

Series.keys() should return an Index and not a list #1101

ClementPinard opened this issue Jan 21, 2025 · 1 comment
Labels
good first issue Series Series data structure

Comments

@ClementPinard
Copy link
Contributor

Describe the bug

a = pd.Series({0:0, 1:1})
reveal_type(a.keys()
print(type(a.keys())

Running pyright on this code gives you

information: Type of "a.keys()" is "list[Unknown]"

Which is normal since it's written explictly here :

def keys(self) -> list: ...

However, if we run it with python, we get pandas.core.indexes.base.Index

Should we replace the linked line from list to Index ?

I have a code that is failing type checking because it call a.keys().tolist(), while it does work as intended.

@ClementPinard ClementPinard changed the title Series.keys() should return an Index and not a series Series.keys() should return an Index and not a list Jan 21, 2025
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 31, 2025

Thanks for the report.

PR with tests welcome.

@Dr-Irv Dr-Irv added good first issue Series Series data structure labels Jan 31, 2025
janlodewijk added a commit to janlodewijk/pandas-stubs that referenced this issue Feb 6, 2025
Imported Index from pandas
and
Changed keys method:
def keys(self) -> Index: ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Series Series data structure
Projects
None yet
Development

No branches or pull requests

2 participants