Skip to content

itertuples doesn't respect name parameter #854

Closed
@davetapley

Description

@davetapley

Describe the bug

Per the docs name is:

The name of the returned namedtuples or None to return regular tuples.

But this repo only gives:

def itertuples(
self, index: _bool = ..., name: _str | None = ...
) -> Iterable[_PandasNamedTuple]: ...

Where:

class _PandasNamedTuple(tuple[Any, ...]):
def __getattr__(self, field: str) -> Scalar: ...

To Reproduce

df = DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
               index=['dog', 'hawk'])
tuples: Iterable[tuple[int, int]] = df.itertuples(name=None)

Pyright:

Expression of type "Iterable[_PandasNamedTuple]" cannot be assigned to declared type "Iterable[tuple[int, int]]"
  "Iterable[_PandasNamedTuple]" is incompatible with "Iterable[tuple[int, int]]"
    Type parameter "_T_co@Iterable" is covariant, but "_PandasNamedTuple" is not a subtype of "tuple[int, int]"
      "_PandasNamedTuple" is incompatible with "tuple[int, int]"
        Tuple size mismatch; expected 2 but received indeterminatePylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)

Please complete the following information:

  • OS: Ubuntu 20.04.6 LTS
  • python 3.11.4
  • pyright v1.1.347
  • pandas-stubs 2.1.4.231227

Additional context

Also notable that the actual returned type is either map or zip for name Pandas or None respectively.

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