Skip to content

DOC: change tuples param for MultiIndex.from_tuples from sequence to iterable #61357

Open
@yangdanny97

Description

@yangdanny97

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.MultiIndex.from_tuples.html#pandas.MultiIndex.from_tuples

The docs currently say this for the tuples parameter:

list / sequence of tuple-likes

Documentation problem

Pandas-stubs annotates the parameter as sequence: https://github.com/pandas-dev/pandas-stubs/blob/main/pandas-stubs/core/indexes/multi.pyi#L49

Pandas source code annotates the parameter as iterable: https://github.com/pandas-dev/pandas/blob/main/pandas/core/indexes/multi.py#L521

Typing the parameter as sequence prevents this pattern from typechecking, even if it works at runtime:

MultiIndex.from_tuples(zip(['a'], ['b']))

This was raised in pandas-dev/pandas-stubs#1158

Suggested fix for documentation

Could we loosen the type annotation in the docs to say iterable? Then I can update pandas-stubs to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions