Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into settingwithcopywarning
# Conflicts: #	pandas/_config/__init__.py #	pandas/core/frame.py #	pandas/core/generic.py #	pandas/core/series.py #	pandas/tests/copy_view/test_chained_assignment_deprecation.py #	pandas/tests/copy_view/test_indexing.py #	pandas/tests/copy_view/test_interp_fillna.py #	pandas/tests/copy_view/test_methods.py #	pandas/tests/copy_view/test_replace.py #	pandas/tests/frame/indexing/test_indexing.py #	pandas/tests/frame/indexing/test_xs.py #	pandas/tests/indexing/multiindex/test_chaining_and_caching.py #	pandas/tests/indexing/multiindex/test_setitem.py #	pandas/tests/indexing/test_chaining_and_caching.py #	pandas/tests/series/accessors/test_dt_accessor.py
  • Loading branch information
phofl committed Feb 4, 2024
commit 60c7ffedd8a855b1acaa64d57ae7d71f7f921d9b
4 changes: 0 additions & 4 deletions pandas/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def using_copy_on_write() -> bool:
return True


def warn_copy_on_write() -> bool:
return False


def using_pyarrow_string_dtype() -> bool:
_mode_options = _global_config["future"]
return _mode_options["infer_string"]
15 changes: 0 additions & 15 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12279,21 +12279,6 @@ def _inplace_method(self, other, op) -> Self:
"""
result = op(self, other)

if (
self.ndim == 1
and result._indexed_same(self)
and result.dtype == self.dtype
and not using_copy_on_write()
and not (warn_copy_on_write() and not warn)
):
# GH#36498 this inplace op can _actually_ be inplace.
# Item "BlockManager" of "Union[BlockManager, SingleBlockManager]" has
# no attribute "setitem_inplace"
self._mgr.setitem_inplace( # type: ignore[union-attr]
slice(None), result._values, warn=warn
)
return self

# this makes sure that we are aligned like the input
# we are updating inplace
self._update_inplace(result.reindex_like(self, copy=False))
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ def __setitem__(self, key, value) -> None:
else:
self._set_with(key, value)

def _set_with_engine(self, key, value, warn: bool = True) -> None:
def _set_with_engine(self, key, value) -> None:
loc = self.index.get_loc(key)

# this is equivalent to self._values[key] = value
Expand Down Expand Up @@ -1365,7 +1365,7 @@ def _set_values(self, key, value) -> None:
if isinstance(key, (Index, Series)):
key = key._values

self._mgr = self._mgr.setitem(indexer=key, value=value, warn=warn)
self._mgr = self._mgr.setitem(indexer=key, value=value)

def _set_value(self, label, value, takeable: bool = False) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pytest

from pandas.compat import PY311
from pandas.errors import ChainedAssignmentError

from pandas import DataFrame
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/copy_view/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ def test_column_as_series_set_with_upcast(backend, warn_copy_on_write):
s[0] = "foo"
expected = Series([1, 2, 3], name="a")
else:
# TODO(CoW-warn) assert the FutureWarning for CoW is also raised
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
s[0] = "foo"
expected = Series(["foo", 2, 3], dtype=object, name="a")
Expand Down
30 changes: 6 additions & 24 deletions pandas/tests/copy_view/test_interp_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,9 @@ def test_fillna_chained_assignment():
df["a"].fillna(100, inplace=True)
tm.assert_frame_equal(df, df_orig)

with tm.raises_chained_assignment_error():
df[["a"]].fillna(100, inplace=True)
tm.assert_frame_equal(df, df_orig)
else:
with tm.assert_produces_warning(None):
df[["a"]].fillna(100, inplace=True)

with tm.assert_produces_warning(None):
df[df.a > 5].fillna(100, inplace=True)

with tm.assert_produces_warning(FutureWarning, match="inplace method"):
df["a"].fillna(100, inplace=True)
with tm.raises_chained_assignment_error():
df[["a"]].fillna(100, inplace=True)
tm.assert_frame_equal(df, df_orig)


@pytest.mark.parametrize("func", ["interpolate", "ffill", "bfill"])
Expand All @@ -401,15 +392,6 @@ def test_interpolate_chained_assignment(func):
getattr(df["a"], func)(inplace=True)
tm.assert_frame_equal(df, df_orig)

with tm.raises_chained_assignment_error():
getattr(df[["a"]], func)(inplace=True)
tm.assert_frame_equal(df, df_orig)
else:
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
getattr(df["a"], func)(inplace=True)

with tm.assert_produces_warning(None):
getattr(df[["a"]], func)(inplace=True)

with tm.assert_produces_warning(None):
getattr(df[df["a"] > 1], func)(inplace=True)
with tm.raises_chained_assignment_error():
getattr(df[["a"]], func)(inplace=True)
tm.assert_frame_equal(df, df_orig)
15 changes: 3 additions & 12 deletions pandas/tests/copy_view/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,18 +1756,9 @@ def test_update_chained_assignment():
df["a"].update(ser2)
tm.assert_frame_equal(df, df_orig)

with tm.raises_chained_assignment_error():
df[["a"]].update(ser2.to_frame())
tm.assert_frame_equal(df, df_orig)
else:
with tm.assert_produces_warning(FutureWarning, match="inplace method"):
df["a"].update(ser2)

with tm.assert_produces_warning(None):
df[["a"]].update(ser2.to_frame())

with tm.assert_produces_warning(None):
df[df["a"] > 1].update(ser2.to_frame())
with tm.raises_chained_assignment_error():
df[["a"]].update(ser2.to_frame())
tm.assert_frame_equal(df, df_orig)


def test_inplace_arithmetic_series(using_copy_on_write):
Expand Down
15 changes: 3 additions & 12 deletions pandas/tests/copy_view/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,9 @@ def test_replace_chained_assignment():
df["a"].replace(1, 100, inplace=True)
tm.assert_frame_equal(df, df_orig)

with tm.raises_chained_assignment_error():
df[["a"]].replace(1, 100, inplace=True)
tm.assert_frame_equal(df, df_orig)
else:
with tm.assert_produces_warning(None):
df[["a"]].replace(1, 100, inplace=True)

with tm.assert_produces_warning(None):
df[df.a > 5].replace(1, 100, inplace=True)

with tm.assert_produces_warning(FutureWarning, match="inplace method"):
df["a"].replace(1, 100, inplace=True)
with tm.raises_chained_assignment_error():
df[["a"]].replace(1, 100, inplace=True)
tm.assert_frame_equal(df, df_orig)


def test_replace_listlike(using_copy_on_write):
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.