Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jbrockmendel opened this issue Feb 8, 2020 · 1 comment
Closed

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

jbrockmendel opened this issue Feb 8, 2020 · 1 comment

Comments

@jbrockmendel
Copy link
Member

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.

@jbrockmendel
Copy link
Member Author

closing as duplicate of #26412

jbrockmendel added a commit to jbrockmendel/pandas that referenced this issue Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant