Skip to content

Commit

Permalink
REGR: revert ExtensionBlock.set to be in-place (#35271)
Browse files Browse the repository at this point in the history
* REGR: revert ExtensionBlock.set to be in-place

Co-authored-by: Simon Hawkins <[email protected]>
Co-authored-by: Tom Augspurger <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2020
1 parent 04e9e0a commit 6302f7b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,6 @@ Indexing
- Bug in :meth:`Series.__getitem__` indexing with non-standard scalars, e.g. ``np.dtype`` (:issue:`32684`)
- Bug in :class:`Index` constructor where an unhelpful error message was raised for NumPy scalars (:issue:`33017`)
- Bug in :meth:`DataFrame.lookup` incorrectly raising an ``AttributeError`` when ``frame.index`` or ``frame.columns`` is not unique; this will now raise a ``ValueError`` with a helpful error message (:issue:`33041`)
- Bug in :meth:`DataFrame.iloc.__setitem__` creating a new array instead of overwriting ``Categorical`` values in-place (:issue:`32831`)
- Bug in :class:`Interval` where a :class:`Timedelta` could not be added or subtracted from a :class:`Timestamp` interval (:issue:`32023`)
- Bug in :meth:`DataFrame.copy` not invalidating _item_cache after copy caused post-copy value updates to not be reflected (:issue:`31784`)
- Fixed regression in :meth:`DataFrame.loc` and :meth:`Series.loc` throwing an error when a ``datetime64[ns, tz]`` value is provided (:issue:`32395`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ def should_store(self, value: ArrayLike) -> bool:

def set(self, locs, values):
assert locs.tolist() == [0]
self.values[:] = values
self.values = values

def putmask(
self, mask, new, inplace: bool = False, axis: int = 0, transpose: bool = False,
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ def test_series_indexing_zerodim_np_array(self):
result = s.iloc[np.array(0)]
assert result == 1

@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/issues/33457")
def test_iloc_setitem_categorical_updates_inplace(self):
# Mixed dtype ensures we go through take_split_path in setitem_with_indexer
cat = pd.Categorical(["A", "B", "C"])
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,3 +1100,13 @@ def test_long_text_missing_labels_inside_loc_error_message_limited():
error_message_regex = "long_missing_label_text_0.*\\\\n.*long_missing_label_text_1"
with pytest.raises(KeyError, match=error_message_regex):
s.loc[["a", "c"] + missing_labels]


def test_setitem_categorical():
# https://github.com/pandas-dev/pandas/issues/35369
df = pd.DataFrame({"h": pd.Series(list("mn")).astype("category")})
df.h = df.h.cat.reorder_categories(["n", "m"])
expected = pd.DataFrame(
{"h": pd.Categorical(["m", "n"]).reorder_categories(["n", "m"])}
)
tm.assert_frame_equal(df, expected)

0 comments on commit 6302f7b

Please sign in to comment.