Skip to content

BUG: setitem with boolean mask and series as value is broken for Series with EA type #37676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 17, 2020
20 changes: 20 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,26 @@ def any_nullable_int_dtype(request):
return request.param


@pytest.fixture(params=tm.ALL_EA_INT_DTYPES + tm.FLOAT_EA_DTYPES)
def any_numeric_dtype(request):
"""
Parameterized fixture for any nullable integer dtype and
any float ea dtypes.

* 'UInt8'
* 'Int8'
* 'UInt16'
* 'Int16'
* 'UInt32'
* 'Int32'
* 'UInt64'
* 'Int64'
* 'Float32'
* 'Float64'
"""
return request.param


@pytest.fixture(params=tm.SIGNED_EA_INT_DTYPES)
def any_signed_nullable_int_dtype(request):
"""
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ def test_setitem_boolean_td64_values_cast_na(self, value):
expected = Series([NaT, 1, 2], dtype="timedelta64[ns]")
tm.assert_series_equal(series, expected)

def test_setitem_boolean_nullable_int_types(self, any_numeric_dtype):
# GH: 26468
ser = Series([5, 6, 7, 8], dtype=any_numeric_dtype)
ser[ser > 6] = Series(range(4), dtype=any_numeric_dtype)
expected = Series([5, 6, 2, 3], dtype=any_numeric_dtype)
tm.assert_series_equal(ser, expected)

ser = Series([5, 6, 7, 8], dtype=any_numeric_dtype)
ser.loc[ser > 6] = Series(range(4), dtype=any_numeric_dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT thats from the reduction bugfix yesterday. im troubleshooting it now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuesday, so not really recently, merged now

tm.assert_series_equal(ser, expected)

ser = Series([5, 6, 7, 8], dtype=any_numeric_dtype)
loc_ser = Series(range(4), dtype=any_numeric_dtype)
ser.loc[ser > 6] = loc_ser.loc[loc_ser > 1]
tm.assert_series_equal(ser, expected)


class TestSetitemViewCopySemantics:
def test_setitem_invalidates_datetime_index_freq(self):
Expand Down