Skip to content

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

@ClementPinard

Description

@ClementPinard

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions