Skip to content

Commit e852bf4

Browse files
jorisvandenbosschesimonjayhawkinsTomAugspurger
authored andcommitted
REGR: revert ExtensionBlock.set to be in-place (#35271)
* REGR: revert ExtensionBlock.set to be in-place Co-authored-by: Simon Hawkins <[email protected]> Co-authored-by: Tom Augspurger <[email protected]>
1 parent 29a733f commit e852bf4

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ Indexing
999999
- Bug in :meth:`Series.__getitem__` indexing with non-standard scalars, e.g. ``np.dtype`` (:issue:`32684`)
10001000
- Bug in :class:`Index` constructor where an unhelpful error message was raised for NumPy scalars (:issue:`33017`)
10011001
- 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`)
1002-
- Bug in :meth:`DataFrame.iloc.__setitem__` creating a new array instead of overwriting ``Categorical`` values in-place (:issue:`32831`)
10031002
- Bug in :class:`Interval` where a :class:`Timedelta` could not be added or subtracted from a :class:`Timestamp` interval (:issue:`32023`)
10041003
- Bug in :meth:`DataFrame.copy` not invalidating _item_cache after copy caused post-copy value updates to not be reflected (:issue:`31784`)
10051004
- Fixed regression in :meth:`DataFrame.loc` and :meth:`Series.loc` throwing an error when a ``datetime64[ns, tz]`` value is provided (:issue:`32395`)

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ def should_store(self, value: ArrayLike) -> bool:
15891589

15901590
def set(self, locs, values):
15911591
assert locs.tolist() == [0]
1592-
self.values[:] = values
1592+
self.values = values
15931593

15941594
def putmask(
15951595
self, mask, new, inplace: bool = False, axis: int = 0, transpose: bool = False,

pandas/tests/indexing/test_iloc.py

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ def test_series_indexing_zerodim_np_array(self):
694694
result = s.iloc[np.array(0)]
695695
assert result == 1
696696

697+
@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/issues/33457")
697698
def test_iloc_setitem_categorical_updates_inplace(self):
698699
# Mixed dtype ensures we go through take_split_path in setitem_with_indexer
699700
cat = pd.Categorical(["A", "B", "C"])

pandas/tests/indexing/test_indexing.py

+10
Original file line numberDiff line numberDiff line change
@@ -1100,3 +1100,13 @@ def test_long_text_missing_labels_inside_loc_error_message_limited():
11001100
error_message_regex = "long_missing_label_text_0.*\\\\n.*long_missing_label_text_1"
11011101
with pytest.raises(KeyError, match=error_message_regex):
11021102
s.loc[["a", "c"] + missing_labels]
1103+
1104+
1105+
def test_setitem_categorical():
1106+
# https://github.com/pandas-dev/pandas/issues/35369
1107+
df = pd.DataFrame({"h": pd.Series(list("mn")).astype("category")})
1108+
df.h = df.h.cat.reorder_categories(["n", "m"])
1109+
expected = pd.DataFrame(
1110+
{"h": pd.Categorical(["m", "n"]).reorder_categories(["n", "m"])}
1111+
)
1112+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)