From 2f9aa6843c8c1018ec9b7d813f32f125dab1e2ed Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 17 Sep 2025 08:19:13 +0200 Subject: [PATCH 1/2] CoW: disable chained assignment detection for Python 3.14 (#62324) Co-authored-by: Nathan Goldbaum --- .github/workflows/unit-tests.yml | 2 -- pandas/_testing/contexts.py | 9 ++++-- pandas/compat/__init__.py | 2 ++ pandas/compat/_constants.py | 2 ++ pandas/core/frame.py | 18 ++++++++---- pandas/core/generic.py | 29 +++++++++++++------ pandas/core/indexing.py | 13 +++++---- pandas/core/series.py | 18 ++++++++---- .../test_chained_assignment_deprecation.py | 8 ++++- 9 files changed, 70 insertions(+), 31 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 73d8b8ffc090d..07f4dd2560601 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -406,5 +406,3 @@ jobs: - name: Run Tests uses: ./.github/actions/run-tests - # TEMP allow this to fail until we fixed all test failures (related to chained assignment warnings) - continue-on-error: true diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index 48616ee134582..482b800f85ef0 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -13,7 +13,10 @@ from pandas._config import using_copy_on_write -from pandas.compat import PYPY +from pandas.compat import ( + PYPY, + WARNING_CHECK_DISABLED, +) from pandas.errors import ChainedAssignmentError from pandas import set_option @@ -204,11 +207,11 @@ def raises_chained_assignment_error(warn=True, extra_warnings=(), extra_match=() return nullcontext() - if PYPY and not extra_warnings: + if (PYPY or WARNING_CHECK_DISABLED) and not extra_warnings: from contextlib import nullcontext return nullcontext() - elif PYPY and extra_warnings: + elif (PYPY or WARNING_CHECK_DISABLED) and extra_warnings: return assert_produces_warning( extra_warnings, match="|".join(extra_match), diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index e7a691dabe1b5..c8554be0a18b1 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -22,6 +22,7 @@ PY312, PY314, PYPY, + WARNING_CHECK_DISABLED, ) import pandas.compat.compressors from pandas.compat.numpy import is_numpy_dev @@ -208,4 +209,5 @@ def get_bz2_file() -> type[pandas.compat.compressors.BZ2File]: "PY312", "PY314", "PYPY", + "WARNING_CHECK_DISABLED", ] diff --git a/pandas/compat/_constants.py b/pandas/compat/_constants.py index 95d74ae2f1a5e..fb011603712c6 100644 --- a/pandas/compat/_constants.py +++ b/pandas/compat/_constants.py @@ -20,6 +20,8 @@ PYPY = platform.python_implementation() == "PyPy" ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "") REF_COUNT = 2 if PY311 else 3 +WARNING_CHECK_DISABLED = PY314 + __all__ = [ "IS64", diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ef48090f02c3f..f8b2465f46d4d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -54,7 +54,10 @@ from pandas._libs.hashtable import duplicated from pandas._libs.lib import is_range_indexer from pandas.compat import PYPY -from pandas.compat._constants import REF_COUNT +from pandas.compat._constants import ( + REF_COUNT, + WARNING_CHECK_DISABLED, +) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv from pandas.errors import ( @@ -4274,12 +4277,12 @@ def isetitem(self, loc, value) -> None: self._iset_item_mgr(loc, arraylike, inplace=False, refs=refs) def __setitem__(self, key, value) -> None: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= 3: warnings.warn( _chained_assignment_msg, ChainedAssignmentError, stacklevel=2 ) - elif not PYPY and not using_copy_on_write(): + elif not PYPY and not WARNING_CHECK_DISABLED and not using_copy_on_write(): if sys.getrefcount(self) <= 3 and ( warn_copy_on_write() or ( @@ -8983,14 +8986,19 @@ def update( 2 3 6.0 """ - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, ChainedAssignmentError, stacklevel=2, ) - elif not PYPY and not using_copy_on_write() and self._is_view_after_cow_rules(): + elif ( + not PYPY + and not WARNING_CHECK_DISABLED + and not using_copy_on_write() + and self._is_view_after_cow_rules() + ): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_warning_method_msg, diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 70b72577dd5d1..10da37cf34e1e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -90,7 +90,10 @@ npt, ) from pandas.compat import PYPY -from pandas.compat._constants import REF_COUNT +from pandas.compat._constants import ( + REF_COUNT, + WARNING_CHECK_DISABLED, +) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv from pandas.errors import ( @@ -7285,7 +7288,7 @@ def fillna( """ inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -7294,6 +7297,7 @@ def fillna( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -7588,7 +7592,7 @@ def ffill( downcast = self._deprecate_downcast(downcast, "ffill") inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -7597,6 +7601,7 @@ def ffill( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -7792,7 +7797,7 @@ def bfill( downcast = self._deprecate_downcast(downcast, "bfill") inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -7801,6 +7806,7 @@ def bfill( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -7963,7 +7969,7 @@ def replace( inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -7972,6 +7978,7 @@ def replace( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -8415,7 +8422,7 @@ def interpolate( inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -8424,6 +8431,7 @@ def interpolate( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -9057,7 +9065,7 @@ def clip( inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -9066,6 +9074,7 @@ def clip( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -10975,7 +10984,7 @@ def where( """ inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -10984,6 +10993,7 @@ def where( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): @@ -11058,7 +11068,7 @@ def mask( ) -> Self | None: inplace = validate_bool_kwarg(inplace, "inplace") if inplace: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, @@ -11067,6 +11077,7 @@ def mask( ) elif ( not PYPY + and not WARNING_CHECK_DISABLED and not using_copy_on_write() and self._is_view_after_cow_rules() ): diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index e9af3536f84c7..c7bab4860411f 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -21,6 +21,7 @@ from pandas._libs.indexing import NDFrameIndexerBase from pandas._libs.lib import item_from_zerodim from pandas.compat import PYPY +from pandas.compat._constants import WARNING_CHECK_DISABLED from pandas.errors import ( AbstractMethodError, ChainedAssignmentError, @@ -881,12 +882,12 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None) -> None: @final def __setitem__(self, key, value) -> None: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self.obj) <= 2: warnings.warn( _chained_assignment_msg, ChainedAssignmentError, stacklevel=2 ) - elif not PYPY and not using_copy_on_write(): + elif not PYPY and not WARNING_CHECK_DISABLED and not using_copy_on_write(): ctr = sys.getrefcount(self.obj) ref_count = 2 if not warn_copy_on_write() and _check_cacher(self.obj): @@ -2575,12 +2576,12 @@ def __getitem__(self, key): return super().__getitem__(key) def __setitem__(self, key, value) -> None: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self.obj) <= 2: warnings.warn( _chained_assignment_msg, ChainedAssignmentError, stacklevel=2 ) - elif not PYPY and not using_copy_on_write(): + elif not PYPY and not WARNING_CHECK_DISABLED and not using_copy_on_write(): ctr = sys.getrefcount(self.obj) ref_count = 2 if not warn_copy_on_write() and _check_cacher(self.obj): @@ -2616,12 +2617,12 @@ def _convert_key(self, key): return key def __setitem__(self, key, value) -> None: - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self.obj) <= 2: warnings.warn( _chained_assignment_msg, ChainedAssignmentError, stacklevel=2 ) - elif not PYPY and not using_copy_on_write(): + elif not PYPY and not WARNING_CHECK_DISABLED and not using_copy_on_write(): ctr = sys.getrefcount(self.obj) ref_count = 2 if not warn_copy_on_write() and _check_cacher(self.obj): diff --git a/pandas/core/series.py b/pandas/core/series.py index cc16c29c6c861..fd6bdde0b09f7 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -39,7 +39,10 @@ ) from pandas._libs.lib import is_range_indexer from pandas.compat import PYPY -from pandas.compat._constants import REF_COUNT +from pandas.compat._constants import ( + REF_COUNT, + WARNING_CHECK_DISABLED, +) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv from pandas.errors import ( @@ -1269,12 +1272,12 @@ def _get_value(self, label, takeable: bool = False): def __setitem__(self, key, value) -> None: warn = True - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= 3: warnings.warn( _chained_assignment_msg, ChainedAssignmentError, stacklevel=2 ) - elif not PYPY and not using_copy_on_write(): + elif not PYPY and not WARNING_CHECK_DISABLED and not using_copy_on_write(): ctr = sys.getrefcount(self) ref_count = 3 if not warn_copy_on_write() and _check_cacher(self): @@ -3621,14 +3624,19 @@ def update(self, other: Series | Sequence | Mapping) -> None: 2 3 dtype: int64 """ - if not PYPY and using_copy_on_write(): + if not PYPY and not WARNING_CHECK_DISABLED and using_copy_on_write(): if sys.getrefcount(self) <= REF_COUNT: warnings.warn( _chained_assignment_method_msg, ChainedAssignmentError, stacklevel=2, ) - elif not PYPY and not using_copy_on_write() and self._is_view_after_cow_rules(): + elif ( + not PYPY + and not WARNING_CHECK_DISABLED + and not using_copy_on_write() + and self._is_view_after_cow_rules() + ): ctr = sys.getrefcount(self) ref_count = REF_COUNT if _check_cacher(self): diff --git a/pandas/tests/copy_view/test_chained_assignment_deprecation.py b/pandas/tests/copy_view/test_chained_assignment_deprecation.py index 11a0e982dbcdb..49f5254f5bab4 100644 --- a/pandas/tests/copy_view/test_chained_assignment_deprecation.py +++ b/pandas/tests/copy_view/test_chained_assignment_deprecation.py @@ -1,7 +1,10 @@ import numpy as np import pytest -from pandas.compat import PY311 +from pandas.compat import ( + PY311, + WARNING_CHECK_DISABLED, +) from pandas.errors import ( ChainedAssignmentError, SettingWithCopyWarning, @@ -150,6 +153,9 @@ def test_series_setitem(indexer, using_copy_on_write, warn_copy_on_write): # using custom check instead of tm.assert_produces_warning because that doesn't # fail if multiple warnings are raised + if WARNING_CHECK_DISABLED: + return + with pytest.warns() as record: df["a"][indexer] = 0 assert len(record) == 1 From 1e22499958aed830141201c7a5e93720ffb8966d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 20 Sep 2025 18:12:13 +0200 Subject: [PATCH 2/2] fix chained inplace method tests --- pandas/_testing/contexts.py | 2 +- pandas/tests/copy_view/test_clip.py | 7 ++++++- pandas/tests/copy_view/test_interp_fillna.py | 12 ++++++++++-- pandas/tests/copy_view/test_methods.py | 15 ++++++++++++--- pandas/tests/copy_view/test_replace.py | 7 ++++++- pandas/tests/frame/methods/test_fillna.py | 6 +++++- pandas/tests/frame/methods/test_interpolate.py | 6 +++++- pandas/tests/frame/test_block_internals.py | 6 +++++- pandas/tests/series/indexing/test_indexing.py | 6 +++++- pandas/tests/series/methods/test_update.py | 6 +++++- 10 files changed, 60 insertions(+), 13 deletions(-) diff --git a/pandas/_testing/contexts.py b/pandas/_testing/contexts.py index 482b800f85ef0..aa409a90a22f8 100644 --- a/pandas/_testing/contexts.py +++ b/pandas/_testing/contexts.py @@ -250,7 +250,7 @@ def assert_cow_warning(warn=True, match=None, **kwargs): """ from pandas._testing import assert_produces_warning - if not warn: + if not warn or WARNING_CHECK_DISABLED: from contextlib import nullcontext return nullcontext() diff --git a/pandas/tests/copy_view/test_clip.py b/pandas/tests/copy_view/test_clip.py index 7c87646424e2f..5c5abdae7a021 100644 --- a/pandas/tests/copy_view/test_clip.py +++ b/pandas/tests/copy_view/test_clip.py @@ -1,5 +1,7 @@ import numpy as np +from pandas.compat import WARNING_CHECK_DISABLED + from pandas import ( DataFrame, option_context, @@ -89,7 +91,10 @@ def test_clip_chained_inplace(using_copy_on_write): df[["a"]].clip(1, 2, inplace=True) tm.assert_frame_equal(df, df_orig) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["a"].clip(1, 2, inplace=True) with tm.assert_produces_warning(None): diff --git a/pandas/tests/copy_view/test_interp_fillna.py b/pandas/tests/copy_view/test_interp_fillna.py index d0c4fa53faab9..0bcc968014242 100644 --- a/pandas/tests/copy_view/test_interp_fillna.py +++ b/pandas/tests/copy_view/test_interp_fillna.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED + from pandas import ( NA, ArrowDtype, @@ -404,7 +406,10 @@ def test_fillna_chained_assignment(using_copy_on_write): with option_context("mode.chained_assignment", None): df[df.a > 5].fillna(100, inplace=True) - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["a"].fillna(100, inplace=True) @@ -421,7 +426,10 @@ def test_interpolate_chained_assignment(using_copy_on_write, func): getattr(df[["a"]], func)(inplace=True) tm.assert_frame_equal(df, df_orig) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): getattr(df["a"], func)(inplace=True) with tm.assert_produces_warning(None): diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index 4934ea745a9f9..2df39a1ec7023 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -1,7 +1,10 @@ import numpy as np import pytest -from pandas.compat import HAS_PYARROW +from pandas.compat import ( + HAS_PYARROW, + WARNING_CHECK_DISABLED, +) from pandas.errors import SettingWithCopyWarning import pandas as pd @@ -1585,7 +1588,10 @@ def test_chained_where_mask(using_copy_on_write, func): getattr(df[["a"]], func)(df["a"] > 2, 5, inplace=True) tm.assert_frame_equal(df, df_orig) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): getattr(df["a"], func)(df["a"] > 2, 5, inplace=True) with tm.assert_produces_warning(None): @@ -1864,7 +1870,10 @@ def test_update_chained_assignment(using_copy_on_write): df[["a"]].update(ser2.to_frame()) tm.assert_frame_equal(df, df_orig) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["a"].update(ser2) with tm.assert_produces_warning(None): diff --git a/pandas/tests/copy_view/test_replace.py b/pandas/tests/copy_view/test_replace.py index c6c9eca47f3f4..70158141d0cee 100644 --- a/pandas/tests/copy_view/test_replace.py +++ b/pandas/tests/copy_view/test_replace.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED + from pandas import ( Categorical, DataFrame, @@ -450,7 +452,10 @@ def test_replace_chained_assignment(using_copy_on_write): with option_context("mode.chained_assignment", None): df[df.a > 5].replace(1, 100, inplace=True) - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["a"].replace(1, 100, inplace=True) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index c0fc72768e27f..b6f4680bff73e 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -1,6 +1,7 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED import pandas.util._test_decorators as td from pandas import ( @@ -58,7 +59,10 @@ def test_fillna_on_column_view(self, using_copy_on_write): df[0].fillna(-1, inplace=True) assert np.isnan(arr[:, 0]).all() else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df[0].fillna(-1, inplace=True) assert (arr[:, 0] == -1).all() diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index ebee19e3de20a..214c7cb229f56 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -3,6 +3,7 @@ from pandas._config import using_string_dtype +from pandas.compat import WARNING_CHECK_DISABLED from pandas.errors import ChainedAssignmentError import pandas.util._test_decorators as td @@ -391,7 +392,10 @@ def test_interp_inplace(self, using_copy_on_write): assert return_value is None tm.assert_frame_equal(result, expected_cow) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): return_value = result["a"].interpolate(inplace=True) assert return_value is None tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index b2fcba50de097..ac3e4f7c9224f 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -7,6 +7,7 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED from pandas.errors import PerformanceWarning import pandas.util._test_decorators as td @@ -411,7 +412,10 @@ def test_update_inplace_sets_valid_block_values(using_copy_on_write): with tm.raises_chained_assignment_error(): df["a"].fillna(1, inplace=True) else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["a"].fillna(1, inplace=True) # check we haven't put a Series into any block.values diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index 3b62f7c4c0549..f153628d32e27 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -5,6 +5,7 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED from pandas.errors import IndexingError from pandas import ( @@ -301,7 +302,10 @@ def test_underlying_data_conversion(using_copy_on_write): df["val"].update(s) expected = df_original else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["val"].update(s) expected = DataFrame( {"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3], "val": [0, 1, 0]} diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index 3f18ae6c13880..b09a58e04947f 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -1,6 +1,7 @@ import numpy as np import pytest +from pandas.compat import WARNING_CHECK_DISABLED import pandas.util._test_decorators as td from pandas import ( @@ -34,7 +35,10 @@ def test_update(self, using_copy_on_write): df["c"].update(Series(["foo"], index=[0])) expected = df_orig else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): + with tm.assert_produces_warning( + FutureWarning if not WARNING_CHECK_DISABLED else None, + match="inplace method", + ): df["c"].update(Series(["foo"], index=[0])) expected = DataFrame( [[1, np.nan, "foo"], [3, 2.0, np.nan]], columns=["a", "b", "c"]