diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index 307543eca2b3e3..6ebe3cb7487ab3 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -9,18 +9,20 @@ class BaseSetitemTests(BaseExtensionTests): - def test_setitem_scalar_series(self, data): - arr = pd.Series(data) - arr[0] = data[1] - assert arr[0] == data[1] - - def test_setitem_sequence(self, data): - arr = pd.Series(data) + def test_setitem_scalar_series(self, data, box_in_series): + if box_in_series: + data = pd.Series(data) + data[0] = data[1] + assert data[0] == data[1] + + def test_setitem_sequence(self, data, box_in_series): + if box_in_series: + data = pd.Series(data) original = data.copy() - arr[[0, 1]] = [data[1], data[0]] - assert arr[0] == original[1] - assert arr[1] == original[0] + data[[0, 1]] = [data[1], data[0]] + assert data[0] == original[1] + assert data[1] == original[0] @pytest.mark.parametrize('as_array', [True, False]) def test_setitem_sequence_mismatched_length_raises(self, data, as_array): @@ -32,22 +34,25 @@ def test_setitem_sequence_mismatched_length_raises(self, data, as_array): xpr = 'cannot set using a {} indexer with a different length' with tm.assert_raises_regex(ValueError, xpr.format('list-like')): ser[[0, 1]] = value + assert ser._values[[0, 1]] == value with tm.assert_raises_regex(ValueError, xpr.format('slice')): ser[slice(3)] = value + assert ser._values[slice(3)] == value - def test_setitem_empty_indxer(self, data): - ser = pd.Series(data) - original = ser.copy() - ser[[]] = [] - self.assert_series_equal(ser, original) - - def test_setitem_sequence_broadcasts(self, data): - arr = pd.Series(data) - - arr[[0, 1]] = data[2] - assert arr[0] == data[2] - assert arr[1] == data[2] + def test_setitem_empty_indxer(self, data, box_in_series): + if box_in_series: + data = pd.Series(data) + original = data.copy() + data[np.array([], dtype=int)] = [] + self.assert_equal(data, original) + + def test_setitem_sequence_broadcasts(self, data, box_in_series): + if box_in_series: + data = pd.Series(data) + data[[0, 1]] = data[2] + assert data[0] == data[2] + assert data[1] == data[2] @pytest.mark.parametrize('setter', ['loc', 'iloc']) def test_setitem_scalar(self, data, setter): diff --git a/pandas/tests/extension/conftest.py b/pandas/tests/extension/conftest.py index 8e397d228a5b6f..7758bd01840aec 100644 --- a/pandas/tests/extension/conftest.py +++ b/pandas/tests/extension/conftest.py @@ -98,3 +98,9 @@ def data_for_grouping(): Where A < B < C and NA is missing """ raise NotImplementedError + + +@pytest.fixture(params=[True, False]) +def box_in_series(request): + """Whether to box the data in a Series""" + return request.param