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
12 changes: 12 additions & 0 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import pytest

from pandas import (
DataFrame,
DatetimeIndex,
MultiIndex,
NaT,
Series,
Timestamp,
array,
date_range,
period_range,
)
Expand Down Expand Up @@ -126,6 +128,16 @@ def test_setitem_boolean_different_order(self, string_series):

tm.assert_series_equal(copy, expected)

def test_setitem_boolean_ea_type(self):
# GH: 26468
df = DataFrame(
{"a": [0, 0, np.nan, np.nan], "b": array(range(4), dtype="Int64")}
)
s = Series(array([1] * 4, dtype="Int64"))
s[df["a"].isna()] = df.loc[df["a"].isna(), "b"]
Copy link
Member

Choose a reason for hiding this comment

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

can you do this without constructing a DataFrame

Copy link
Member Author

Choose a reason for hiding this comment

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

Avoided the DataFrame construction. Checked, that this raised the same error as reported in the issue.

expected = Series([1, 1, 2, 3], dtype="Int64")
tm.assert_series_equal(s, expected)


class TestSetitemViewCopySemantics:
def test_setitem_invalidates_datetime_index_freq(self):
Expand Down