Skip to content

DataFrame.loc: __getitem__[int] allowed, __setitem__[int] forbidden  #817

@clo-vis

Description

@clo-vis
from pandas import DataFrame

data = {"col1": [1, 2], "col2": [3, 4]}

df = DataFrame(data=data, index=["a", "b"])
print(df.loc["a"])
df.loc["a"] = None
print(df)

df2 = DataFrame(data=data, index=[97, 98])
print(df2.loc[97])
df2.loc[97] = None  # error 
print(df)

The line print(df2.loc[97]) is allowed
The line df2.loc[97] = None is not. (mypy: "No overload variant of "__setitem__" of "_LocIndexerFrame" matches argument types "int", "None")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions