-
-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Description
Describe the bug
No overload for DataFrame.loc[Series[bool], Sequence[Hashable]]
or DataFrame.loc[Series[bool], Index[Hashable]]
To Reproduce
Provide a minimal runnable pandas
example that is not properly checked by the stubs.
from collections.abc import Sequence
from typing import cast, reveal_type
import pandas as pd
a = cast(Sequence[str], ["a", "b"])
ind = pd.Index(a)
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
mask = pd.Series([True, False])
reveal_type(df.loc[mask, a])
reveal_type(df.loc[mask, ind])
Indicate which type checker you are using (mypy
or pyright
).
pyright
Show the error message received from that type checker while checking your example.
loc.py:12:13 - warning: No overloads for "__getitem__" match the provided arguments (reportCallIssue)
loc.py:12:13 - warning: Argument of type "tuple[Series[bool], Sequence[str]]" cannot be assigned to parameter "idx" of type "tuple[Scalar, slice[Any, Any, Any]]" in function "__getitem__"
"tuple[Series[bool], Sequence[str]]" is not assignable to "tuple[Scalar, slice[Any, Any, Any]]"
Tuple entry 1 is incorrect type
Type "Series[bool]" is not assignable to type "Scalar"
"Series[bool]" is not assignable to "str"
"Series[bool]" is not assignable to "bytes"
"Series[bool]" is not assignable to "date"
"Series[bool]" is not assignable to "datetime"
"Series[bool]" is not assignable to "timedelta" (reportArgumentType)
loc.py:12:13 - information: Type of "df.loc[mask, a]" is "Unknown"
loc.py:13:13 - warning: No overloads for "__getitem__" match the provided arguments (reportCallIssue)
loc.py:13:13 - warning: Argument of type "tuple[Series[bool], Index[str]]" cannot be assigned to parameter "idx" of type "tuple[Scalar, slice[Any, Any, Any]]" in function "__getitem__"
"tuple[Series[bool], Index[str]]" is not assignable to "tuple[Scalar, slice[Any, Any, Any]]"
Tuple entry 1 is incorrect type
Type "Series[bool]" is not assignable to type "Scalar"
"Series[bool]" is not assignable to "str"
"Series[bool]" is not assignable to "bytes"
"Series[bool]" is not assignable to "date"
"Series[bool]" is not assignable to "datetime"
"Series[bool]" is not assignable to "timedelta" (reportArgumentType)
loc.py:13:13 - information: Type of "df.loc[mask, ind]" is "Unknown"
Please complete the following information
- OS: Windows
- OS Version: 11
- python version: 3.13.4
- version of type checker: 1.1.403
- version of installed
pandas-stubs
: 2.3.0.250703
Additional context
None
Metadata
Metadata
Assignees
Labels
No labels