Skip to content

Commit 23c9bf9

Browse files
phoflyeshsurya
authored andcommitted
Regression modifying obj with all false indexer (pandas-dev#40999)
1 parent 1047768 commit 23c9bf9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/core/indexing.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from pandas.core.construction import array as pd_array
4949
from pandas.core.indexers import (
5050
check_array_indexer,
51+
is_empty_indexer,
5152
is_exact_shape_match,
5253
is_list_like_indexer,
5354
length_of_indexer,
@@ -1882,7 +1883,11 @@ def _setitem_single_column(self, loc: int, value, plane_indexer):
18821883
# GH#6149 (null slice), GH#10408 (full bounds)
18831884
if com.is_null_slice(pi) or com.is_full_slice(pi, len(self.obj)):
18841885
ser = value
1885-
elif is_array_like(value) and is_exact_shape_match(ser, value):
1886+
elif (
1887+
is_array_like(value)
1888+
and is_exact_shape_match(ser, value)
1889+
and not is_empty_indexer(pi, value)
1890+
):
18861891
if is_list_like(pi):
18871892
ser = value[np.argsort(pi)]
18881893
else:

pandas/tests/frame/indexing/test_setitem.py

+8
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ def test_setitem_boolean_indexing(self):
903903
with pytest.raises(ValueError, match="Item wrong length"):
904904
df1[df1.index[:-1] > 2] = -1
905905

906+
def test_loc_setitem_all_false_boolean_two_blocks(self):
907+
# GH#40885
908+
df = DataFrame({"a": [1, 2], "b": [3, 4], "c": "a"})
909+
expected = df.copy()
910+
indexer = Series([False, False], name="c")
911+
df.loc[indexer, ["b"]] = DataFrame({"b": [5, 6]}, index=[0, 1])
912+
tm.assert_frame_equal(df, expected)
913+
906914

907915
class TestDataFrameSetitemCopyViewSemantics:
908916
def test_setitem_always_copy(self, float_frame):

0 commit comments

Comments
 (0)