-
-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Description
Describe the bug
DataFrame.loc
does not like assigning Enum
s.
I think this is related to #1288. I do not mean to be annoying, and the example came from our real use cases.
To Reproduce
Provide a minimal runnable pandas
example that is not properly checked by the stubs.
from enum import Enum, auto
import pandas as pd
class Thing(Enum):
A = auto()
data = pd.DataFrame(index=[0, 1])
data.loc[:, "a"] = Thing.A
Indicate which type checker you are using (mypy
or pyright
)
pyright
Show the error message received from that type checker while checking your example
attempt.py
attempt.py:11:1 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
attempt.py:11:1 - error: Argument of type "Literal[Thing.A]" cannot be assigned to parameter "value" of type "Scalar | ArrayLike | NAType | NaTType | Series[Any] | DataFrame | list[Unknown] | Mapping[Hashable, Scalar | NAType | NaTType] | None" in function "__setitem__"
Type "Literal[Thing.A]" is not assignable to type "Scalar | ArrayLike | NAType | NaTType | Series[Any] | DataFrame | list[Unknown] | Mapping[Hashable, Scalar | NAType | NaTType] | None"
"Literal[Thing.A]" is not assignable to "str"
"Literal[Thing.A]" is not assignable to "bytes"
"Literal[Thing.A]" is not assignable to "date"
"Literal[Thing.A]" is not assignable to "datetime"
"Literal[Thing.A]" is not assignable to "timedelta"
"Literal[Thing.A]" is not assignable to "datetime64[date | int | None]"
"Literal[Thing.A]" is not assignable to "timedelta64[timedelta | int | None]" (reportArgumentType)
2 errors, 0 warnings, 0 informations
Please complete the following information
- OS:
Windows
- OS Version:
11
- python version:
3.13.4
- version of type checker:
1.1.404
- version of installed
pandas-stubs
:2.3.2.250827
Additional context
None
Metadata
Metadata
Assignees
Labels
No labels