Skip to content

Unable to use include_groups=False in df.groupby.apply in version 2.3.0.250703 #1284

@vanitak96

Description

@vanitak96

Describe the bug

I am having typing issues with defining include_groups=False inside pandas.core.groupby.DataFrameGroupBy.apply after upgrading to the latest version of pandas-stubs (from 2.2.3.250527 to 2.3.0.250703

e.g.

result =  data.groupby(groupby).apply(
      group_function,
      include_groups=False, 
)

This now triggers the following typing issues:

error: No overloads for "apply" match the provided arguments (reportCallIssue)
error: No parameter named "include_groups" (reportCallIssue)

Based on pandas 2.3+ documentation, only setting include_groups to True is deprecated while setting it to False is still allowed https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.apply.html#pandas.core.groupby.DataFrameGroupBy.apply

Is there a reason that pandas-stubs has removed the ability to define this keyword argument altogether? I can always ignore the typing warning but we are using this in many places and it feels wrong to add typing: ignore in all these places without understanding the reasoning.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
df = pd.DataFrame(
        [["a", 12, 12], ["a", 14, 18], ["b", 15, 19]],
        columns=["tag", "count_start", "count_end"],
    )

df.groupby("tag").apply(
    lambda x: (x["count_end"] - x["count_start"]).sum(), include_groups=False
)
  1. Indicate which type checker you are using (mypy or pyright).

Using pyright 1.1.403

  1. Show the error message received from that type checker while checking your example.
error: No overloads for "apply" match the provided arguments (reportCallIssue)
error: No parameter named "include_groups" (reportCallIssue)

Please complete the following information:

  • OS: MacOS
  • OS Version: macOS Sequoia 15.4.1
  • python version: 3.11.7
  • version of type checker: pyright 1.1.403
  • version of installed pandas-stubs: 2.3.0.250703

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