Skip to content

Commit 7cbc9f4

Browse files
Backport PR #48711 on branch 1.5.x (REGR: Regression in DataFrame.loc when setting df with all True indexer) (#48717)
Backport PR #48711: REGR: Regression in DataFrame.loc when setting df with all True indexer Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 8b6b5b4 commit 7cbc9f4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v1.5.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17+
- Fixed Regression in :meth:`DataFrame.loc` when setting values as a :class:`DataFrame` with all ``True`` indexer (:issue:`48701`)
1718
- Regression in :func:`.read_csv` causing an ``EmptyDataError`` when using an UTF-8 file handle that was already read from (:issue:`48646`)
1819
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
1920
-

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
19821982
and self.obj.shape[0] == value.shape[0]
19831983
and not is_empty_indexer(pi)
19841984
):
1985-
if is_list_like(pi):
1985+
if is_list_like(pi) and not is_bool_dtype(pi):
19861986
value = value[np.argsort(pi)]
19871987
else:
19881988
# in case of slice

pandas/tests/frame/indexing/test_indexing.py

+9
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,15 @@ def test_loc_named_tuple_for_midx(self):
14051405
)
14061406
tm.assert_frame_equal(result, expected)
14071407

1408+
@pytest.mark.parametrize("col", [{}, {"name": "a"}])
1409+
def test_loc_setitem_reordering_with_all_true_indexer(self, col):
1410+
# GH#48701
1411+
n = 17
1412+
df = DataFrame({**col, "x": range(n), "y": range(n)})
1413+
expected = df.copy()
1414+
df.loc[n * [True], ["x", "y"]] = df[["x", "y"]]
1415+
tm.assert_frame_equal(df, expected)
1416+
14081417

14091418
class TestDataFrameIndexingUInt64:
14101419
def test_setitem(self, uint64_frame):

0 commit comments

Comments
 (0)