Skip to content

groupby.size may return DataFrame in as_index=False #652

@MarcoGorelli

Description

@MarcoGorelli

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
  2. Indicate which type checker you are using (mypy or pyright).
  3. Show the error message received from that type checker while checking your example.

t.py

import pandas as pd

df = pd.DataFrame({'a': [1,2,3]})
reveal_type(df.groupby('a', as_index=False).size())
$ mypy t.py
t.py:4: note: Revealed type is "pandas.core.series.Series[builtins.int]"

However, it is in fact a DataFrame

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS] linux
  • OS Version [e.g. 22] Linux DESKTOP-U8OKFP3 5.10.102.1-microsoft-standard-WSL2 Tasks to complete before making this repo public #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • python version 3.8
  • version of type checker
  • version of installed pandas-stubs
$ pip freeze | grep pandas
pandas==2.0.0
pandas-flavor==0.5.0
pandas-stubs==2.0.0.230412

Additional context
Add any other context about the problem here.

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