Skip to content

Series index argument should accept iterables of certain types #1255

Open
@Dr-Irv

Description

@Dr-Irv

Describe the bug
For the index argument, we should support iterables, but need to be careful that we don't allow plain strings.

index={"a":3, "c": 4}

s1 = pd.Series([1, 2], index=index)
s2 = pd.Series([1, 2], index=index.keys())

t = pd.Series([1,2], index="ab")  # This should fail

Currently, s1 and s2 are rejected by pyright, but should be accepted. t is rejected as well, but I'm including it because any change we make has to make sure this still fails.

To do this, we could modify the AxesData type in _typing.pyi to include Iterable[SeriesDType], but if we do that, then a plain str is accepted. To avoid that problem, I think adding a Series.__new__() overload with index: str returning Never right at the top (and similar for Index.__new__() with the data argument) would force that to be rejected.

The above tests should be included in a PR, where s1 and s2 are accepted, but t is not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions