Skip to content

__setitem__ should accept a dictionary #1203

Closed
@bersbersbers

Description

@bersbersbers

Describe the bug
__setitem__ does not accept a dictionary

To Reproduce

import pandas as pd

df = pd.DataFrame(columns=["X"])
df.loc[0] = {"X": 0}
print(df)
>mypy --version
mypy 1.15.0 (compiled: yes)

>mypy bug.py
bug.py:4: error: No overload variant of "__setitem__" of "_LocIndexerFrame" matches argument types "int", "dict[str, int]"  [call-overload]
bug.py:4: note: Possible overload variants:
bug.py:4: note:     def [ScalarT: str | bytes | date | datetime | timedelta | <7 more items> | complex] __setitem__(self, Series[builtins.bool] | ndarray[tuple[int, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | str_ | <9 more items>, str | bytes | date | datetime | timedelta | <15 more items> | None, /) -> None
bug.py:4: note:     def __setitem__(self, tuple[tuple[Index[Any] | Series[builtins.bool] | ndarray[tuple[int, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | list[Any] | slice[Any, Any, Any] | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex, ...], ...], Hashable], str | bytes | date | datetime | timedelta | <14 more items> | None, /) -> None
Found 1 error in 1 file (checked 1 source file)
>pyright --version
pyright 1.1.400

>pyright bug.py
bug.py
  bug.py:4:1 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
  bug.py:4:1 - error: Argument of type "dict[str, int]" cannot be assigned to parameter "value" of type "Scalar | ArrayLike | NAType | NaTType | Series[Unknown] | DataFrame | list[Unknown] | None" in function "__setitem__"
    Type "dict[str, int]" is not assignable to type "Scalar | ArrayLike | NAType | NaTType | Series[Unknown] | DataFrame | list[Unknown] | None"
      "dict[str, int]" is not assignable to "str"
      "dict[str, int]" is not assignable to "bytes"
      "dict[str, int]" is not assignable to "date"
      "dict[str, int]" is not assignable to "datetime"
      "dict[str, int]" is not assignable to "timedelta"
      "dict[str, int]" is not assignable to "datetime64[date | int | None]"
      "dict[str, int]" is not assignable to "timedelta64[timedelta | int | None]" (reportArgumentType)
2 errors, 0 warnings, 0 informations
>python --version
Python 3.13.2
>uv pip freeze | findstr "pandas"
pandas==2.2.3
pandas-stubs==2.2.3.250308

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockedRequires external dependency before progressingmypy bugRequires mypy to fix a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions