Skip to content

DataFrame.loc does not like assigning Enums #1361

@cmp0xff

Description

@cmp0xff

Describe the bug

DataFrame.loc does not like assigning Enums.

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

No one assigned

    Labels

    DataFrameDataFrame data structureIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions