-
-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Labels
Description
Describe the bug
A clear and concise description of what the bug is.
It seems like we are missing some overloads for aggregate in groupby when we use unpacking of dictionary.
The other issue is that is seems like pyright
and mypy
are not recognizing the same type when unpacking a dictionary, mypy
reads it correctly as tuple[str, dict[str, str]]
while pyright
sees it as dict[str, str]
.
Considering this issue is it something we would like to support and if so at what cost?
To Reproduce
- Provide a minimal runnable
pandas
example that is not properly checked by the stubs. - Indicate which type checker you are using (
mypy
orpyright
). - Show the error message received from that type checker while checking your example.
import pandas as pd
df = pd.DataFrame(
{
"a": [1, 2, 3],
"b": [4, 5, 6],
"c": [7, 8, 9],
}
)
dico = {"a":("a", "mean")}
df.groupby("b").agg(a= ("a", "mean")) # passes fine
df.groupby("b").agg(**dico) # create warnings and fails linter
This is the errors:
/Users/loic/Documents/Code/pandas-stubs/main/tests/test_frame.py
/Users/loic/Documents/Code/pandas-stubs/main/tests/test_frame.py:4705:5 - error: No overloads for "aggregate" match the provided arguments (reportCallIssue)
/Users/loic/Documents/Code/pandas-stubs/main/tests/test_frame.py:4705:27 - error: Argument of type "tuple[str, str]" cannot be assigned to parameter "func" of type "Literal['size']" in function "aggregate"
"tuple[str, str]" is not assignable to "Literal['size']" (reportArgumentType)
2 errors, 0 warnings, 0 informations
tests/test_frame.py:4705: error: No overload variant matches argument type "dict[str, tuple[str, str]]" [call-overload]
tests/test_frame.py:4705: note: Possible overload variants:
tests/test_frame.py:4705: note: def aggregate(self, func: Literal['size']) -> Series[Any]
tests/test_frame.py:4705: note: def aggregate(self, func: Callable[..., Any] | str | ufunc | list[Callable[..., Any] | str | ufunc] | Mapping[Any, Callable[..., Any] | str | ufunc | list[Callable[..., Any] | str | ufunc]] | None = ..., *args: Any, engine: Literal['cython', 'numba'] | None = ..., engine_kwargs: _WindowingNumbaKwargs | None = ..., **kwargs: Any) -> DataFrame
Please complete the following information:
- OS: MacOS
- OS Version 15.6.1
- python version 3.13
- version of type checker 1.17.1
- version of installed
pandas-stubs
main
Additional context
Add any other context about the problem here.