Skip to content

Commit 430a509

Browse files
committed
Regression: Series.loc.setitem raising with all false indexer and series on rhs (pandas-dev#45784)
1 parent ca6c0ce commit 430a509

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v1.4.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Fixed regressions
2020
- Regression in :meth:`DataFrame.iat` setting values leading to not propagating correctly in subsequent lookups (:issue:`45684`)
2121
- Regression when setting values with :meth:`DataFrame.loc` losing :class:`Index` name if :class:`DataFrame` was empty before (:issue:`45621`)
2222
- Regression in :meth:`~Index.join` with overlapping :class:`IntervalIndex` raising an ``InvalidIndexError`` (:issue:`45661`)
23+
- Regression in :meth:`Series.loc.__setitem__` raising with all ``False`` indexer and :class:`Series` on the right hand side (:issue:`45778`)
2324
- Regression in :func:`read_sql` with a DBAPI2 connection that is not an instance of ``sqlite3.Connection`` incorrectly requiring SQLAlchemy be installed (:issue:`45660`)
2425
-
2526

pandas/core/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,8 @@ def ravel(i):
21692169
# we have a frame, with multiple indexers on both axes; and a
21702170
# series, so need to broadcast (see GH5206)
21712171
if sum_aligners == self.ndim and all(is_sequence(_) for _ in indexer):
2172-
if is_empty_indexer(indexer[0]):
2172+
# TODO: This is hacky, align Series and DataFrame behavior GH#45778
2173+
if obj.ndim == 2 and is_empty_indexer(indexer[0]):
21732174
return ser._values.copy()
21742175
ser = ser.reindex(obj.axes[0][indexer[0]], copy=True)._values
21752176

pandas/tests/series/indexing/test_indexing.py

+9
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ def test_frozenset_index():
321321
assert s[idx1] == 3
322322

323323

324+
def test_loc_setitem_all_false_indexer():
325+
# GH#45778
326+
ser = Series([1, 2], index=["a", "b"])
327+
expected = ser.copy()
328+
rhs = Series([6, 7], index=["a", "b"])
329+
ser.loc[ser > 100] = rhs
330+
tm.assert_series_equal(ser, expected)
331+
332+
324333
class TestDeprecatedIndexers:
325334
@pytest.mark.parametrize("key", [{1}, {1: 1}])
326335
def test_getitem_dict_and_set_deprecated(self, key):

0 commit comments

Comments
 (0)