diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index a8b63f97141c2..ff7064b760d88 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -476,9 +476,7 @@ def use_inf_as_na_cb(key) -> None: "copy_on_write", # Get the default from an environment variable, if set, otherwise defaults # to False. This environment variable can be set for testing. - "warn" - if os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "warn" - else os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "1", + "warn", copy_on_write_doc, validator=is_one_of_factory([True, False, "warn"]), ) diff --git a/pandas/tests/apply/test_invalid_arg.py b/pandas/tests/apply/test_invalid_arg.py index 80b2cce8c1dbc..b10b8503c9220 100644 --- a/pandas/tests/apply/test_invalid_arg.py +++ b/pandas/tests/apply/test_invalid_arg.py @@ -149,7 +149,7 @@ def test_transform_axis_1_raises(): Series([1]).transform("sum", axis=1) -def test_apply_modify_traceback(): +def test_apply_modify_traceback(warn_copy_on_write): data = DataFrame( { "A": [ @@ -206,7 +206,8 @@ def transform(row): msg = "'float' object has no attribute 'startswith'" with pytest.raises(AttributeError, match=msg): - data.apply(transform, axis=1) + with tm.assert_cow_warning(warn_copy_on_write): + data.apply(transform, axis=1) @pytest.mark.parametrize(