- information: Type of "ddf.groupby(["a", "b"]).size()" is "Unknown"
c:\Code\pandas-stubs\play\issue1044.py:3:37 - error: Cannot access attribute "size" for class "DataFrameGroupBy[tuple[Unknown, ...], bool]"
Could not bind method "size" because "DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to parameter "self"
"DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to "DataFrameGroupBy[tuple[Unknown, ...], Literal[True]]"
Type parameter "_TT@DataFrameGroupBy" is invariant, but "bool" is not the same as "Literal[True]"
Could not bind method "size" because "DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to parameter "self"
"DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to "DataFrameGroupBy[tuple[Unknown, ...], Literal[False]]"
Type parameter "_TT@DataFrameGroupBy" is invariant, but "bool" is not the same as "Literal[False]"
Could not bind method "size" because "DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to parameter "self"
"DataFrameGroupBy[tuple[Unknown, ...], bool]" is not assignable to "DataFrameGroupBy[Timestamp, Literal[True]]" (reportAttributeAccessIssue)
mypy reports
note: Revealed type is "Any"
The fix here is that any of the methods in frame.pyi for def groupby() that return DataFrameGroupBy[SOMETYPE, bool] need to be split into 2 where there is one overload that returns DataFrameGroupBy[SOMETYPE, True] and another that returns DataFrameGroupBy[SOMETYPE, False] like is done with DataFrameGroupBy[Scalar, True] and DataFrameGroupBy[Scalar, False] .
Please complete the following information:
OS: Windows 11
python version 3.10
version of type checker pyright 1.1.389, mypy 1.13.0
version of installed pandas-stubs: Dev version
Additional context
This was missed in PR #1014 by @loicdiridollou . Hopefully he can fix soon, since the prerelease of VS Code pylance has this bug.
Describe the bug
pyright reports
mypy reports
The fix here is that any of the methods in
frame.pyi
fordef groupby()
that returnDataFrameGroupBy[SOMETYPE, bool]
need to be split into 2 where there is one overload that returnsDataFrameGroupBy[SOMETYPE, True]
and another that returnsDataFrameGroupBy[SOMETYPE, False]
like is done withDataFrameGroupBy[Scalar, True]
andDataFrameGroupBy[Scalar, False]
.Please complete the following information:
pandas-stubs
: Dev versionAdditional context
This was missed in PR #1014 by @loicdiridollou . Hopefully he can fix soon, since the prerelease of VS Code pylance has this bug.