Skip to content

Commit

Permalink
REGR: Regression in DataFrame.loc when setting df with all True index…
Browse files Browse the repository at this point in the history
…er (#48711)
  • Loading branch information
phofl authored Sep 22, 2022
1 parent 6b9d0f7 commit 26d1cec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ including other versions of pandas.

Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed Regression in :meth:`DataFrame.loc` when setting values as a :class:`DataFrame` with all ``True`` indexer (:issue:`48701`)
- Regression in :func:`.read_csv` causing an ``EmptyDataError`` when using an UTF-8 file handle that was already read from (:issue:`48646`)
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
-
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer) -> None:
and self.obj.shape[0] == value.shape[0]
and not is_empty_indexer(pi)
):
if is_list_like(pi):
if is_list_like(pi) and not is_bool_dtype(pi):
value = value[np.argsort(pi)]
else:
# in case of slice
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,15 @@ def test_loc_named_tuple_for_midx(self):
)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("col", [{}, {"name": "a"}])
def test_loc_setitem_reordering_with_all_true_indexer(self, col):
# GH#48701
n = 17
df = DataFrame({**col, "x": range(n), "y": range(n)})
expected = df.copy()
df.loc[n * [True], ["x", "y"]] = df[["x", "y"]]
tm.assert_frame_equal(df, expected)


class TestDataFrameIndexingUInt64:
def test_setitem(self, uint64_frame):
Expand Down

0 comments on commit 26d1cec

Please sign in to comment.