Skip to content

BUG/API: df.loc[a, b] = c allows positional slice for a #31810

Closed
@jbrockmendel

Description

@jbrockmendel
dti = pd.date_range("2016-01-01", periods=5)
df = pd.DataFrame(np.random.randn(5, 2), index=dti, columns=["A", "B"])

>>> df.loc[4:6, "A"]
TypeError: cannot do slice indexing on DatetimeIndex with these indexers [4] of type int

>>> df.loc[4:6, "A"] = 0
# works as if we did df.iloc[4:6, 0] = 0

In this case there are plenty of alternatives that amount to doing df["A"].iloc[4:6] = 0, but this isnt robust to mixed-dtype frames, so I'm not sure if we have a supported way of doing this correctly.

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