Skip to content

WIP set full column if using self.index in loc #55910

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,9 @@ def _convert_to_indexer(self, key, axis: AxisInt):
if isinstance(key, slice):
return labels._convert_slice_indexer(key, kind="loc")

if key is self.obj.index:
return slice(None, None, None)

if (
isinstance(key, tuple)
and not isinstance(labels, MultiIndex)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,3 +1351,11 @@ def test_frame_setitem_empty_dataframe(self):
index=Index([], dtype="datetime64[ns]", name="date"),
)
tm.assert_frame_equal(df, expected)

def test_setitem_frame_with_dataframes_own_index(self):
# https://github.com/pandas-dev/pandas/issues/55791
df1 = DataFrame({"a": [1]})
df2 = DataFrame({"d": [True]})
df1.loc[df1.index, df2.columns] = df2
expected = DataFrame({"a": [1], "d": [True]})
tm.assert_frame_equal(df1, expected)