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

itertuples doesn't respect name parameter #854

Closed
davetapley opened this issue Jan 18, 2024 · 2 comments · Fixed by #915
Closed

itertuples doesn't respect name parameter #854

davetapley opened this issue Jan 18, 2024 · 2 comments · Fixed by #915

Comments

@davetapley
Copy link
Contributor

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.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 18, 2024

Thanks for the report. I think we need to add an @overload on itertuples() for when name = None that returns a tuple[Any, ...]

@davetapley
Copy link
Contributor Author

@Dr-Irv I can do a PR, I need to finish #818 anyway :)

mutricyl pushed a commit to mutricyl/pandas-stubs that referenced this issue Apr 28, 2024
Dr-Irv pushed a commit that referenced this issue Apr 29, 2024
* add overload for itertuples with name None, resolves #854

* allow positional name

---------

Co-authored-by: Laurent Mutricy <laurent.mutricy@ekium.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants