diff --git a/doc/source/whatsnew/v1.4.1.rst b/doc/source/whatsnew/v1.4.1.rst index 3dd0fcdb5b87d3..067cdfbbd550c0 100644 --- a/doc/source/whatsnew/v1.4.1.rst +++ b/doc/source/whatsnew/v1.4.1.rst @@ -20,6 +20,7 @@ Fixed regressions - Regression in :meth:`DataFrame.iat` setting values leading to not propagating correctly in subsequent lookups (:issue:`45684`) - Regression when setting values with :meth:`DataFrame.loc` losing :class:`Index` name if :class:`DataFrame` was empty before (:issue:`45621`) - Regression in :meth:`~Index.join` with overlapping :class:`IntervalIndex` raising an ``InvalidIndexError`` (:issue:`45661`) +- Regression in :meth:`Series.loc.__setitem__` raising with all ``False`` indexer and :class:`Series` on the right hand side (:issue:`45778`) - Regression in :func:`read_sql` with a DBAPI2 connection that is not an instance of ``sqlite3.Connection`` incorrectly requiring SQLAlchemy be installed (:issue:`45660`) - diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 5af87e3eaf2da1..941220f25e12fc 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2169,7 +2169,8 @@ def ravel(i): # we have a frame, with multiple indexers on both axes; and a # series, so need to broadcast (see GH5206) if sum_aligners == self.ndim and all(is_sequence(_) for _ in indexer): - if is_empty_indexer(indexer[0]): + # TODO: This is hacky, align Series and DataFrame behavior GH#45778 + if obj.ndim == 2 and is_empty_indexer(indexer[0]): return ser._values.copy() ser = ser.reindex(obj.axes[0][indexer[0]], copy=True)._values diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index 3c83ac4e1f623b..3a8e14576a55d5 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -321,6 +321,15 @@ def test_frozenset_index(): assert s[idx1] == 3 +def test_loc_setitem_all_false_indexer(): + # GH#45778 + ser = Series([1, 2], index=["a", "b"]) + expected = ser.copy() + rhs = Series([6, 7], index=["a", "b"]) + ser.loc[ser > 100] = rhs + tm.assert_series_equal(ser, expected) + + class TestDeprecatedIndexers: @pytest.mark.parametrize("key", [{1}, {1: 1}]) def test_getitem_dict_and_set_deprecated(self, key):