BUG/API: Series[mask] = (item,) unpacking item #44265
Labels
Bug
Indexing
Related to indexing on series/frames, not to indexes themselves
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
Issue Description
This behavior occurs because
Series.__setitem__
goes throughSeries._where
in cases where the key is a boolean mask. It then ends up going throughManager.putmask
, which usesnp.putmask
semantics (mostly) that repeat/broadcast a listlike value.AFAICT this repeat/broadcasting makes sense for
Series.where
andSeries.mask
, but not forSeries.__setitem__
. I think this behavior is largely accidental. If we disable this behavior inSeries.__setitem__
, 86 tests break. Of these, 84 aretests.series.indexing.test_where.test_downcast
, and the PR (#4195) that introduced that test was aboutwhere
, not__setitem__
. The other two tests I tentatively think are breaking because of the particular way I've disabled the broadcasting.Expected Behavior
ser[mask] = (10,)
should raise.Installed Versions
Replace this line with the output of pd.show_versions()
The text was updated successfully, but these errors were encountered: