-
-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Description
Describe the bug
The following code works but mypy complains with
Invalid index type "tuple[Hashable, str]" for "_AtIndexerFrame"; expected type "Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>" [index]
and pyright comlains with:
error: Argument of type "tuple[Hashable, Literal['uuid']]" cannot be assigned to parameter "idx" of type "Series[bool] | np_ndarray_bool | list[bool] | str | str_ | _IndexSliceTuple[Unknown] | list[ScalarT@__setitem__] | int | int_ | integer[Any] | unsignedinteger[Any] | signedinteger[Any] | int8 | slice[Any, Any, Any]" in function "__setitem__"
Type "tuple[Hashable, Literal['uuid']]" is not assignable to type "Series[bool] | np_ndarray_bool | list[bool] | str | str_ | _IndexSliceTuple[Unknown] | list[ScalarT@__setitem__] | int | int_ | integer[Any] | unsignedinteger[Any] | signedinteger[Any] | int8 | slice[Any, Any, Any]"
"tuple[Hashable, Literal['uuid']]" is not assignable to "int"
"tuple[Hashable, Literal['uuid']]" is not assignable to "str"
"tuple[Hashable, Literal['uuid']]" is not assignable to "str_"
"tuple[Hashable, Literal['uuid']]" is not assignable to "Series[bool]"
"tuple[Hashable, Literal['uuid']]" is not assignable to "integer[Any]"
"tuple[Hashable, Literal['uuid']]" is not assignable to "list[ScalarT@__setitem__]"
"tuple[Hashable, Literal['uuid']]" is not assignable to "list[bool]" (reportArgumentType)
To Reproduce
import pandas as pd
df = pd.DataFrame({"A": ["B", "B"]})
print(df)
# A
# 0 B
# 1 B
for index, row in df.iterrows():
df.at[index, "A"] = "C"
print(df)
# A
# 0 C
# 1 C
The same happens if loc
is used. Adding
assert isinstance(index, int)
before assigning solves it.
Please complete the following information:
- OS: Linux
- OS Version: Debian 12
- python 3.11
- version of type checker: mypy & pyright
- version of installed
pandas-stubs
:pandas 2.3.2
andpandas-stubs 2.3.2.250827
Metadata
Metadata
Assignees
Labels
No labels