From 9e5d754ba7ab010551157cbdf0c7b7891408fde7 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Sun, 4 Feb 2024 23:55:54 +0000 Subject: [PATCH] CoW: Remove copy-on-write conditions from frame tests --- pandas/tests/frame/indexing/test_getitem.py | 9 +--- pandas/tests/frame/indexing/test_indexing.py | 47 ++++------------- pandas/tests/frame/indexing/test_insert.py | 13 ++--- pandas/tests/frame/indexing/test_setitem.py | 35 ++++--------- pandas/tests/frame/indexing/test_xs.py | 32 ++++-------- pandas/tests/frame/methods/test_align.py | 7 +-- pandas/tests/frame/methods/test_cov_corr.py | 13 ++--- pandas/tests/frame/methods/test_fillna.py | 39 +++----------- .../tests/frame/methods/test_interpolate.py | 47 ++++++----------- pandas/tests/frame/methods/test_quantile.py | 13 ++--- pandas/tests/frame/methods/test_reindex.py | 19 ++----- pandas/tests/frame/methods/test_rename.py | 7 +-- pandas/tests/frame/methods/test_set_axis.py | 29 ++--------- .../tests/frame/methods/test_sort_values.py | 13 ++--- .../frame/methods/test_to_dict_of_blocks.py | 21 ++------ pandas/tests/frame/methods/test_to_numpy.py | 15 ++---- pandas/tests/frame/methods/test_transpose.py | 15 ++---- pandas/tests/frame/methods/test_update.py | 16 ++---- pandas/tests/frame/methods/test_values.py | 26 +++------- pandas/tests/frame/test_api.py | 8 +-- pandas/tests/frame/test_arithmetic.py | 12 ++--- pandas/tests/frame/test_block_internals.py | 52 ++++--------------- pandas/tests/frame/test_constructors.py | 39 +++----------- 23 files changed, 129 insertions(+), 398 deletions(-) diff --git a/pandas/tests/frame/indexing/test_getitem.py b/pandas/tests/frame/indexing/test_getitem.py index 73683922bcc92..25d6e06a4c675 100644 --- a/pandas/tests/frame/indexing/test_getitem.py +++ b/pandas/tests/frame/indexing/test_getitem.py @@ -391,18 +391,13 @@ def test_getitem_empty_frame_with_boolean(self): df2 = df[df > 0] tm.assert_frame_equal(df, df2) - def test_getitem_returns_view_when_column_is_unique_in_df( - self, using_copy_on_write - ): + def test_getitem_returns_view_when_column_is_unique_in_df(self): # GH#45316 df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "a", "b"]) df_orig = df.copy() view = df["b"] view.loc[:] = 100 - if using_copy_on_write: - expected = df_orig - else: - expected = DataFrame([[1, 2, 100], [4, 5, 100]], columns=["a", "a", "b"]) + expected = df_orig tm.assert_frame_equal(df, expected) def test_getitem_frozenset_unique_in_column(self): diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index b48ad7e3481b9..97176b20376ff 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -565,9 +565,7 @@ def test_getitem_setitem_integer_slice_keyerrors(self): with pytest.raises(KeyError, match=r"^3$"): df2.loc[3:11] = 0 - def test_fancy_getitem_slice_mixed( - self, float_frame, float_string_frame, using_copy_on_write - ): + def test_fancy_getitem_slice_mixed(self, float_frame, float_string_frame): sliced = float_string_frame.iloc[:, -3:] assert sliced["D"].dtype == np.float64 @@ -579,13 +577,7 @@ def test_fancy_getitem_slice_mixed( assert np.shares_memory(sliced["C"]._values, float_frame["C"]._values) sliced.loc[:, "C"] = 4.0 - if not using_copy_on_write: - assert (float_frame["C"] == 4).all() - - # with the enforcement of GH#45333 in 2.0, this remains a view - np.shares_memory(sliced["C"]._values, float_frame["C"]._values) - else: - tm.assert_frame_equal(float_frame, original) + tm.assert_frame_equal(float_frame, original) def test_getitem_setitem_non_ix_labels(self): df = DataFrame(range(20), index=date_range("2020-01-01", periods=20)) @@ -1053,7 +1045,7 @@ def test_iloc_row(self): expected = df.reindex(df.index[[1, 2, 4, 6]]) tm.assert_frame_equal(result, expected) - def test_iloc_row_slice_view(self, using_copy_on_write): + def test_iloc_row_slice_view(self): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), index=range(0, 20, 2) ) @@ -1067,11 +1059,6 @@ def test_iloc_row_slice_view(self, using_copy_on_write): exp_col = original[2].copy() subset.loc[:, 2] = 0.0 - if not using_copy_on_write: - exp_col._values[4:8] = 0.0 - - # With the enforcement of GH#45333 in 2.0, this remains a view - assert np.shares_memory(df[2], subset[2]) tm.assert_series_equal(df[2], exp_col) def test_iloc_col(self): @@ -1097,32 +1084,20 @@ def test_iloc_col(self): expected = df.reindex(columns=df.columns[[1, 2, 4, 6]]) tm.assert_frame_equal(result, expected) - def test_iloc_col_slice_view(self, using_copy_on_write): + def test_iloc_col_slice_view(self): df = DataFrame( np.random.default_rng(2).standard_normal((4, 10)), columns=range(0, 20, 2) ) original = df.copy() subset = df.iloc[:, slice(4, 8)] - if not using_copy_on_write: - # verify slice is view - assert np.shares_memory(df[8]._values, subset[8]._values) - - subset.loc[:, 8] = 0.0 - - assert (df[8] == 0).all() - - # with the enforcement of GH#45333 in 2.0, this remains a view - assert np.shares_memory(df[8]._values, subset[8]._values) - else: - if using_copy_on_write: - # verify slice is view - assert np.shares_memory(df[8]._values, subset[8]._values) - subset[8] = 0.0 - # subset changed - assert (subset[8] == 0).all() - # but df itself did not change (setitem replaces full column) - tm.assert_frame_equal(df, original) + # verify slice is view + assert np.shares_memory(df[8]._values, subset[8]._values) + subset[8] = 0.0 + # subset changed + assert (subset[8] == 0).all() + # but df itself did not change (setitem replaces full column) + tm.assert_frame_equal(df, original) def test_loc_duplicates(self): # gh-17105 diff --git a/pandas/tests/frame/indexing/test_insert.py b/pandas/tests/frame/indexing/test_insert.py index b9fc5dc195026..2558e8314664a 100644 --- a/pandas/tests/frame/indexing/test_insert.py +++ b/pandas/tests/frame/indexing/test_insert.py @@ -71,7 +71,7 @@ def test_insert_with_columns_dups(self): ) tm.assert_frame_equal(df, exp) - def test_insert_item_cache(self, using_copy_on_write): + def test_insert_item_cache(self): df = DataFrame(np.random.default_rng(2).standard_normal((4, 3))) ser = df[0] expected_warning = PerformanceWarning @@ -80,14 +80,9 @@ def test_insert_item_cache(self, using_copy_on_write): for n in range(100): df[n + 3] = df[1] * n - if using_copy_on_write: - ser.iloc[0] = 99 - assert df.iloc[0, 0] == df[0][0] - assert df.iloc[0, 0] != 99 - else: - ser.values[0] = 99 - assert df.iloc[0, 0] == df[0][0] - assert df.iloc[0, 0] == 99 + ser.iloc[0] = 99 + assert df.iloc[0, 0] == df[0][0] + assert df.iloc[0, 0] != 99 def test_insert_EA_no_warning(self): # PerformanceWarning about fragmented frame should not be raised when diff --git a/pandas/tests/frame/indexing/test_setitem.py b/pandas/tests/frame/indexing/test_setitem.py index 2df01b2cdb721..20e7651f8af83 100644 --- a/pandas/tests/frame/indexing/test_setitem.py +++ b/pandas/tests/frame/indexing/test_setitem.py @@ -324,7 +324,7 @@ def test_frame_setitem_existing_datetime64_col_other_units(self, unit): df["dates"] = vals assert (df["dates"].values == ex_vals).all() - def test_setitem_dt64tz(self, timezone_frame, using_copy_on_write): + def test_setitem_dt64tz(self, timezone_frame): df = timezone_frame idx = df["B"].rename("foo") @@ -345,10 +345,7 @@ def test_setitem_dt64tz(self, timezone_frame, using_copy_on_write): tm.assert_extension_array_equal(v1, v2) v1base = v1._ndarray.base v2base = v2._ndarray.base - if not using_copy_on_write: - assert v1base is None or (id(v1base) != id(v2base)) - else: - assert id(v1base) == id(v2base) + assert id(v1base) == id(v2base) # with nan df2 = df.copy() @@ -844,7 +841,7 @@ def test_setitem_object_array_of_tzaware_datetimes(self, idx, expected): class TestDataFrameSetItemWithExpansion: - def test_setitem_listlike_views(self, using_copy_on_write): + def test_setitem_listlike_views(self): # GH#38148 df = DataFrame({"a": [1, 2, 3], "b": [4, 4, 6]}) @@ -857,10 +854,7 @@ def test_setitem_listlike_views(self, using_copy_on_write): # edit in place the first column to check view semantics df.iloc[0, 0] = 100 - if using_copy_on_write: - expected = Series([1, 2, 3], name="a") - else: - expected = Series([100, 2, 3], name="a") + expected = Series([1, 2, 3], name="a") tm.assert_series_equal(ser, expected) def test_setitem_string_column_numpy_dtype_raising(self): @@ -870,7 +864,7 @@ def test_setitem_string_column_numpy_dtype_raising(self): expected = DataFrame([[1, 2, 5], [3, 4, 6]], columns=[0, 1, "0 - Name"]) tm.assert_frame_equal(df, expected) - def test_setitem_empty_df_duplicate_columns(self, using_copy_on_write): + def test_setitem_empty_df_duplicate_columns(self): # GH#38521 df = DataFrame(columns=["a", "b", "b"], dtype="float64") df.loc[:, "a"] = list(range(2)) @@ -1199,7 +1193,7 @@ def test_setitem_always_copy(self, float_frame): assert notna(s[5:10]).all() @pytest.mark.parametrize("consolidate", [True, False]) - def test_setitem_partial_column_inplace(self, consolidate, using_copy_on_write): + def test_setitem_partial_column_inplace(self, consolidate): # This setting should be in-place, regardless of whether frame is # single-block or multi-block # GH#304 this used to be incorrectly not-inplace, in which case @@ -1215,18 +1209,11 @@ def test_setitem_partial_column_inplace(self, consolidate, using_copy_on_write): else: assert len(df._mgr.blocks) == 2 - zvals = df["z"]._values - df.loc[2:, "z"] = 42 expected = Series([np.nan, np.nan, 42, 42], index=df.index, name="z") tm.assert_series_equal(df["z"], expected) - # check setting occurred in-place - if not using_copy_on_write: - tm.assert_numpy_array_equal(zvals, expected.values) - assert np.shares_memory(zvals, df["z"]._values) - def test_setitem_duplicate_columns_not_inplace(self): # GH#39510 cols = ["A", "B"] * 2 @@ -1298,7 +1285,7 @@ def test_setitem_not_operating_inplace(self, value, set_value, indexer): df[indexer] = set_value tm.assert_frame_equal(view, expected) - def test_setitem_column_update_inplace(self, using_copy_on_write): + def test_setitem_column_update_inplace(self): # https://github.com/pandas-dev/pandas/issues/47172 labels = [f"c{i}" for i in range(10)] @@ -1308,12 +1295,8 @@ def test_setitem_column_update_inplace(self, using_copy_on_write): with tm.raises_chained_assignment_error(): for label in df.columns: df[label][label] = 1 - if not using_copy_on_write: - # diagonal values all updated - assert np.all(values[np.arange(10), np.arange(10)] == 1) - else: - # original dataframe not updated - assert np.all(values[np.arange(10), np.arange(10)] == 0) + # original dataframe not updated + assert np.all(values[np.arange(10), np.arange(10)] == 0) def test_setitem_column_frame_as_category(self): # GH31581 diff --git a/pandas/tests/frame/indexing/test_xs.py b/pandas/tests/frame/indexing/test_xs.py index 96ae1050ed15a..4878f74bd152e 100644 --- a/pandas/tests/frame/indexing/test_xs.py +++ b/pandas/tests/frame/indexing/test_xs.py @@ -58,7 +58,7 @@ def test_xs_dt_error(self, datetime_frame): ): datetime_frame.xs(datetime_frame.index[0] - BDay()) - def test_xs_other(self, float_frame, using_copy_on_write): + def test_xs_other(self, float_frame): float_frame_orig = float_frame.copy() # xs get column series = float_frame.xs("A", axis=1) @@ -68,12 +68,9 @@ def test_xs_other(self, float_frame, using_copy_on_write): # view is returned if possible series = float_frame.xs("A", axis=1) series[:] = 5 - if using_copy_on_write: - # but with CoW the view shouldn't propagate mutations - tm.assert_series_equal(float_frame["A"], float_frame_orig["A"]) - assert not (expected == 5).all() - else: - assert (expected == 5).all() + # The view shouldn't propagate mutations + tm.assert_series_equal(float_frame["A"], float_frame_orig["A"]) + assert not (expected == 5).all() def test_xs_corner(self): # pathological mixed-type reordering case @@ -363,7 +360,7 @@ def test_xs_droplevel_false(self): expected = DataFrame({"a": [1]}) tm.assert_frame_equal(result, expected) - def test_xs_droplevel_false_view(self, using_copy_on_write): + def test_xs_droplevel_false_view(self): # GH#37832 df = DataFrame([[1, 2, 3]], columns=Index(["a", "b", "c"])) result = df.xs("a", axis=1, drop_level=False) @@ -371,26 +368,15 @@ def test_xs_droplevel_false_view(self, using_copy_on_write): assert np.shares_memory(result.iloc[:, 0]._values, df.iloc[:, 0]._values) df.iloc[0, 0] = 2 - if using_copy_on_write: - # with copy on write the subset is never modified - expected = DataFrame({"a": [1]}) - else: - # modifying original df also modifies result when having a single block - expected = DataFrame({"a": [2]}) + # The subset is never modified + expected = DataFrame({"a": [1]}) tm.assert_frame_equal(result, expected) - # with mixed dataframe, modifying the parent doesn't modify result - # TODO the "split" path behaves differently here as with single block df = DataFrame([[1, 2.5, "a"]], columns=Index(["a", "b", "c"])) result = df.xs("a", axis=1, drop_level=False) df.iloc[0, 0] = 2 - if using_copy_on_write: - # with copy on write the subset is never modified - expected = DataFrame({"a": [1]}) - else: - # FIXME: iloc does not update the array inplace using - # "split" path - expected = DataFrame({"a": [1]}) + # The subset is never modified + expected = DataFrame({"a": [1]}) tm.assert_frame_equal(result, expected) def test_xs_list_indexer_droplevel_false(self): diff --git a/pandas/tests/frame/methods/test_align.py b/pandas/tests/frame/methods/test_align.py index 1f5d960de40c1..aa539dd0b2dbe 100644 --- a/pandas/tests/frame/methods/test_align.py +++ b/pandas/tests/frame/methods/test_align.py @@ -48,15 +48,12 @@ def test_frame_align_aware(self): assert new1.index.tz is timezone.utc assert new2.index.tz is timezone.utc - def test_align_float(self, float_frame, using_copy_on_write): + def test_align_float(self, float_frame): af, bf = float_frame.align(float_frame) assert af._mgr is not float_frame._mgr af, bf = float_frame.align(float_frame, copy=False) - if not using_copy_on_write: - assert af._mgr is float_frame._mgr - else: - assert af._mgr is not float_frame._mgr + assert af._mgr is not float_frame._mgr # axis = 0 other = float_frame.iloc[:-5, :3] diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 2a50137c2d6ef..8e73fbf152e79 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -207,7 +207,7 @@ def test_corr_nullable_integer(self, nullable_column, other_column, method): expected = DataFrame(np.ones((2, 2)), columns=["a", "b"], index=["a", "b"]) tm.assert_frame_equal(result, expected) - def test_corr_item_cache(self, using_copy_on_write): + def test_corr_item_cache(self): # Check that corr does not lead to incorrect entries in item_cache df = DataFrame({"A": range(10)}) @@ -218,15 +218,8 @@ def test_corr_item_cache(self, using_copy_on_write): _ = df.corr(numeric_only=True) - if using_copy_on_write: - ser.iloc[0] = 99 - assert df.loc[0, "A"] == 0 - else: - # Check that the corr didn't break link between ser and df - ser.values[0] = 99 - assert df.loc[0, "A"] == 99 - assert df["A"] is ser - assert df.values[0, 0] == 99 + ser.iloc[0] = 99 + assert df.loc[0, "A"] == 0 @pytest.mark.parametrize("length", [2, 20, 200, 2000]) def test_corr_for_constant_columns(self, length): diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index df38ddc6c3116..efb462416e132 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -20,7 +20,7 @@ class TestFillNA: - def test_fillna_dict_inplace_nonunique_columns(self, using_copy_on_write): + def test_fillna_dict_inplace_nonunique_columns(self): df = DataFrame( {"A": [np.nan] * 3, "B": [NaT, Timestamp(1), NaT], "C": [np.nan, "foo", 2]} ) @@ -35,27 +35,16 @@ def test_fillna_dict_inplace_nonunique_columns(self, using_copy_on_write): ) expected.columns = ["A", "A", "A"] tm.assert_frame_equal(df, expected) - - # TODO: what's the expected/desired behavior with CoW? - if not using_copy_on_write: - assert tm.shares_memory(df.iloc[:, 0], orig.iloc[:, 0]) assert not tm.shares_memory(df.iloc[:, 1], orig.iloc[:, 1]) - if not using_copy_on_write: - assert tm.shares_memory(df.iloc[:, 2], orig.iloc[:, 2]) - def test_fillna_on_column_view(self, using_copy_on_write): + def test_fillna_on_column_view(self): # GH#46149 avoid unnecessary copies arr = np.full((40, 50), np.nan) df = DataFrame(arr, copy=False) - if using_copy_on_write: - with tm.raises_chained_assignment_error(): - df[0].fillna(-1, inplace=True) - assert np.isnan(arr[:, 0]).all() - else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): - df[0].fillna(-1, inplace=True) - assert (arr[:, 0] == -1).all() + with tm.raises_chained_assignment_error(): + df[0].fillna(-1, inplace=True) + assert np.isnan(arr[:, 0]).all() # i.e. we didn't create a new 49-column block assert len(df._mgr.arrays) == 1 @@ -107,17 +96,6 @@ def test_fillna_mixed_float(self, mixed_float_frame): result = mf.fillna(method="pad") _check_mixed_float(result, dtype={"C": None}) - def test_fillna_empty(self, using_copy_on_write): - if using_copy_on_write: - pytest.skip("condition is unnecessary complex and is deprecated anyway") - # empty frame (GH#2778) - df = DataFrame(columns=["x"]) - for m in ["pad", "backfill"]: - msg = "Series.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - df.x.fillna(method=m, inplace=True) - df.x.fillna(method=m) - def test_fillna_different_dtype(self, using_infer_string): # with different dtype (GH#3386) df = DataFrame( @@ -746,7 +724,7 @@ def test_fillna_inplace_with_columns_limit_and_value(self): tm.assert_frame_equal(df, expected) @pytest.mark.parametrize("val", [-1, {"x": -1, "y": -1}]) - def test_inplace_dict_update_view(self, val, using_copy_on_write): + def test_inplace_dict_update_view(self, val): # GH#47188 df = DataFrame({"x": [np.nan, 2], "y": [np.nan, 2]}) df_orig = df.copy() @@ -754,10 +732,7 @@ def test_inplace_dict_update_view(self, val, using_copy_on_write): df.fillna(val, inplace=True) expected = DataFrame({"x": [-1, 2.0], "y": [-1.0, 2]}) tm.assert_frame_equal(df, expected) - if using_copy_on_write: - tm.assert_frame_equal(result_view, df_orig) - else: - tm.assert_frame_equal(result_view, expected) + tm.assert_frame_equal(result_view, df_orig) def test_single_block_df_with_horizontal_axis(self): # GH 47713 diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 5eb9aee2ffb15..483194a46ce56 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -68,7 +68,7 @@ def test_interpolate_inplace(self, frame_or_series, request): @pytest.mark.xfail( using_pyarrow_string_dtype(), reason="interpolate doesn't work for string" ) - def test_interp_basic(self, using_copy_on_write): + def test_interp_basic(self): df = DataFrame( { "A": [1, 2, np.nan, 4], @@ -93,12 +93,8 @@ def test_interp_basic(self, using_copy_on_write): # check we didn't operate inplace GH#45791 cvalues = df["C"]._values dvalues = df["D"].values - if using_copy_on_write: - assert np.shares_memory(cvalues, result["C"]._values) - assert np.shares_memory(dvalues, result["D"]._values) - else: - assert not np.shares_memory(cvalues, result["C"]._values) - assert not np.shares_memory(dvalues, result["D"]._values) + assert np.shares_memory(cvalues, result["C"]._values) + assert np.shares_memory(dvalues, result["D"]._values) with tm.assert_produces_warning(FutureWarning, match=msg): res = df.interpolate(inplace=True) @@ -371,38 +367,25 @@ def test_interp_raise_on_all_object_dtype(self): with pytest.raises(TypeError, match=msg): df.interpolate() - def test_interp_inplace(self, using_copy_on_write): + def test_interp_inplace(self): df = DataFrame({"a": [1.0, 2.0, np.nan, 4.0]}) - expected = DataFrame({"a": [1.0, 2.0, 3.0, 4.0]}) - expected_cow = df.copy() + expected = df.copy() result = df.copy() - if using_copy_on_write: - with tm.raises_chained_assignment_error(): - return_value = result["a"].interpolate(inplace=True) - assert return_value is None - tm.assert_frame_equal(result, expected_cow) - else: - with tm.assert_produces_warning(FutureWarning, match="inplace method"): - return_value = result["a"].interpolate(inplace=True) - assert return_value is None - tm.assert_frame_equal(result, expected) + with tm.raises_chained_assignment_error(): + return_value = result["a"].interpolate(inplace=True) + assert return_value is None + tm.assert_frame_equal(result, expected) result = df.copy() msg = "The 'downcast' keyword in Series.interpolate is deprecated" - if using_copy_on_write: - with tm.assert_produces_warning( - (FutureWarning, ChainedAssignmentError), match=msg - ): - return_value = result["a"].interpolate(inplace=True, downcast="infer") - assert return_value is None - tm.assert_frame_equal(result, expected_cow) - else: - with tm.assert_produces_warning(FutureWarning, match=msg): - return_value = result["a"].interpolate(inplace=True, downcast="infer") - assert return_value is None - tm.assert_frame_equal(result, expected.astype("int64")) + with tm.assert_produces_warning( + (FutureWarning, ChainedAssignmentError), match=msg + ): + return_value = result["a"].interpolate(inplace=True, downcast="infer") + assert return_value is None + tm.assert_frame_equal(result, expected) def test_interp_inplace_row(self): # GH 10395 diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index e31e29b1b0cb2..48d55b2954360 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -723,7 +723,7 @@ def test_quantile_empty_no_columns(self, interp_method): expected.columns.name = "captain tightpants" tm.assert_frame_equal(result, expected) - def test_quantile_item_cache(self, interp_method, using_copy_on_write): + def test_quantile_item_cache(self, interp_method): # previous behavior incorrect retained an invalid _item_cache entry interpolation, method = interp_method df = DataFrame( @@ -735,14 +735,9 @@ def test_quantile_item_cache(self, interp_method, using_copy_on_write): df.quantile(numeric_only=False, interpolation=interpolation, method=method) - if using_copy_on_write: - ser.iloc[0] = 99 - assert df.iloc[0, 0] == df["A"][0] - assert df.iloc[0, 0] != 99 - else: - ser.values[0] = 99 - assert df.iloc[0, 0] == df["A"][0] - assert df.iloc[0, 0] == 99 + ser.iloc[0] = 99 + assert df.iloc[0, 0] == df["A"][0] + assert df.iloc[0, 0] != 99 def test_invalid_method(self): with pytest.raises(ValueError, match="Invalid method: foo"): diff --git a/pandas/tests/frame/methods/test_reindex.py b/pandas/tests/frame/methods/test_reindex.py index da6d69f36f900..76d80e87bdeb5 100644 --- a/pandas/tests/frame/methods/test_reindex.py +++ b/pandas/tests/frame/methods/test_reindex.py @@ -173,7 +173,7 @@ def test_reindex_copies(self): result2 = df.reindex(columns=cols, index=df.index, copy=True) assert not np.shares_memory(result2[0]._values, df[0]._values) - def test_reindex_copies_ea(self, using_copy_on_write): + def test_reindex_copies_ea(self): # https://github.com/pandas-dev/pandas/pull/51197 # also ensure to honor copy keyword for ExtensionDtypes N = 10 @@ -184,17 +184,11 @@ def test_reindex_copies_ea(self, using_copy_on_write): np.random.default_rng(2).shuffle(cols) result = df.reindex(columns=cols, copy=True) - if using_copy_on_write: - assert np.shares_memory(result[0].array._data, df[0].array._data) - else: - assert not np.shares_memory(result[0].array._data, df[0].array._data) + assert np.shares_memory(result[0].array._data, df[0].array._data) # pass both columns and index result2 = df.reindex(columns=cols, index=df.index, copy=True) - if using_copy_on_write: - assert np.shares_memory(result2[0].array._data, df[0].array._data) - else: - assert not np.shares_memory(result2[0].array._data, df[0].array._data) + assert np.shares_memory(result2[0].array._data, df[0].array._data) def test_reindex_date_fill_value(self): # passing date to dt64 is deprecated; enforced in 2.0 to cast to object @@ -602,7 +596,7 @@ def test_reindex_sparse(self): ) tm.assert_frame_equal(result, expected) - def test_reindex(self, float_frame, using_copy_on_write): + def test_reindex(self, float_frame): datetime_series = Series( np.arange(30, dtype=np.float64), index=date_range("2020-01-01", periods=30) ) @@ -644,10 +638,7 @@ def test_reindex(self, float_frame, using_copy_on_write): # Same index, copies values but not index if copy=False newFrame = float_frame.reindex(float_frame.index, copy=False) - if using_copy_on_write: - assert newFrame.index.is_(float_frame.index) - else: - assert newFrame.index is float_frame.index + assert newFrame.index.is_(float_frame.index) # length zero newFrame = float_frame.reindex([]) diff --git a/pandas/tests/frame/methods/test_rename.py b/pandas/tests/frame/methods/test_rename.py index b965a5d973fb6..996fc30552bc4 100644 --- a/pandas/tests/frame/methods/test_rename.py +++ b/pandas/tests/frame/methods/test_rename.py @@ -164,16 +164,13 @@ def test_rename_multiindex(self): renamed = df.rename(index={"foo1": "foo3", "bar2": "bar3"}, level=0) tm.assert_index_equal(renamed.index, new_index) - def test_rename_nocopy(self, float_frame, using_copy_on_write): + def test_rename_nocopy(self, float_frame): renamed = float_frame.rename(columns={"C": "foo"}, copy=False) assert np.shares_memory(renamed["foo"]._values, float_frame["C"]._values) renamed.loc[:, "foo"] = 1.0 - if using_copy_on_write: - assert not (float_frame["C"] == 1.0).all() - else: - assert (float_frame["C"] == 1.0).all() + assert not (float_frame["C"] == 1.0).all() def test_rename_inplace(self, float_frame): float_frame.rename(columns={"C": "foo"}) diff --git a/pandas/tests/frame/methods/test_set_axis.py b/pandas/tests/frame/methods/test_set_axis.py index 8d249bc7b7fa4..8c42498b45621 100644 --- a/pandas/tests/frame/methods/test_set_axis.py +++ b/pandas/tests/frame/methods/test_set_axis.py @@ -21,7 +21,7 @@ def test_set_axis(self, obj): result = obj.set_axis(new_index, axis=0) tm.assert_equal(expected, result) - def test_set_axis_copy(self, obj, using_copy_on_write): + def test_set_axis_copy(self, obj): # Test copy keyword GH#47932 new_index = list("abcd")[: len(obj)] @@ -32,16 +32,6 @@ def test_set_axis_copy(self, obj, using_copy_on_write): result = obj.set_axis(new_index, axis=0, copy=True) tm.assert_equal(expected, result) assert result is not obj - # check we DID make a copy - if not using_copy_on_write: - if obj.ndim == 1: - assert not tm.shares_memory(result, obj) - else: - assert not any( - tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) - for i in range(obj.shape[1]) - ) - result = obj.set_axis(new_index, axis=0, copy=False) tm.assert_equal(expected, result) assert result is not obj @@ -58,20 +48,11 @@ def test_set_axis_copy(self, obj, using_copy_on_write): result = obj.set_axis(new_index, axis=0) tm.assert_equal(expected, result) assert result is not obj - if using_copy_on_write: - # check we DID NOT make a copy - if obj.ndim == 1: - assert tm.shares_memory(result, obj) - else: - assert any( - tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) - for i in range(obj.shape[1]) - ) - # check we DID make a copy - elif obj.ndim == 1: - assert not tm.shares_memory(result, obj) + # check we DID NOT make a copy + if obj.ndim == 1: + assert tm.shares_memory(result, obj) else: - assert not any( + assert any( tm.shares_memory(result.iloc[:, i], obj.iloc[:, i]) for i in range(obj.shape[1]) ) diff --git a/pandas/tests/frame/methods/test_sort_values.py b/pandas/tests/frame/methods/test_sort_values.py index 768c85644c977..c146dcc9c2d71 100644 --- a/pandas/tests/frame/methods/test_sort_values.py +++ b/pandas/tests/frame/methods/test_sort_values.py @@ -592,7 +592,7 @@ def test_sort_values_nat_na_position_default(self): result = expected.sort_values(["A", "date"]) tm.assert_frame_equal(result, expected) - def test_sort_values_item_cache(self, using_copy_on_write): + def test_sort_values_item_cache(self): # previous behavior incorrect retained an invalid _item_cache entry df = DataFrame( np.random.default_rng(2).standard_normal((4, 3)), columns=["A", "B", "C"] @@ -603,14 +603,9 @@ def test_sort_values_item_cache(self, using_copy_on_write): df.sort_values(by="A") - if using_copy_on_write: - ser.iloc[0] = 99 - assert df.iloc[0, 0] == df["A"][0] - assert df.iloc[0, 0] != 99 - else: - ser.values[0] = 99 - assert df.iloc[0, 0] == df["A"][0] - assert df.iloc[0, 0] == 99 + ser.iloc[0] = 99 + assert df.iloc[0, 0] == df["A"][0] + assert df.iloc[0, 0] != 99 def test_sort_values_reshaping(self): # GH 39426 diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index 19001f10e37e4..0f1f643209db0 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -10,8 +10,7 @@ class TestToDictOfBlocks: - @pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning") - def test_no_copy_blocks(self, float_frame, using_copy_on_write): + def test_no_copy_blocks(self, float_frame): # GH#9607 df = DataFrame(float_frame, copy=True) column = df.columns[0] @@ -23,15 +22,10 @@ def test_no_copy_blocks(self, float_frame, using_copy_on_write): _last_df = _df if column in _df: _df.loc[:, column] = _df[column] + 1 + assert _last_df is not None and not _last_df[column].equals(df[column]) - if not using_copy_on_write: - # make sure we did change the original DataFrame - assert _last_df is not None and _last_df[column].equals(df[column]) - else: - assert _last_df is not None and not _last_df[column].equals(df[column]) - -def test_to_dict_of_blocks_item_cache(using_copy_on_write): +def test_to_dict_of_blocks_item_cache(): # Calling to_dict_of_blocks should not poison item_cache df = DataFrame({"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"]}) df["c"] = NumpyExtensionArray(np.array([1, 2, None, 3], dtype=object)) @@ -42,15 +36,8 @@ def test_to_dict_of_blocks_item_cache(using_copy_on_write): df._to_dict_of_blocks() - if using_copy_on_write: - with pytest.raises(ValueError, match="read-only"): - ser.values[0] = "foo" - else: - # Check that the to_dict_of_blocks didn't break link between ser and df + with pytest.raises(ValueError, match="read-only"): ser.values[0] = "foo" - assert df.loc[0, "b"] == "foo" - - assert df["b"] is ser def test_set_change_dtype_slice(): diff --git a/pandas/tests/frame/methods/test_to_numpy.py b/pandas/tests/frame/methods/test_to_numpy.py index d92af2775922b..d38bc06260a0e 100644 --- a/pandas/tests/frame/methods/test_to_numpy.py +++ b/pandas/tests/frame/methods/test_to_numpy.py @@ -20,23 +20,16 @@ def test_to_numpy_dtype(self): result = df.to_numpy(dtype="int64") tm.assert_numpy_array_equal(result, expected) - def test_to_numpy_copy(self, using_copy_on_write): + def test_to_numpy_copy(self): arr = np.random.default_rng(2).standard_normal((4, 3)) df = DataFrame(arr) - if using_copy_on_write: - assert df.values.base is not arr - assert df.to_numpy(copy=False).base is df.values.base - else: - assert df.values.base is arr - assert df.to_numpy(copy=False).base is arr + assert df.values.base is not arr + assert df.to_numpy(copy=False).base is df.values.base assert df.to_numpy(copy=True).base is not arr # we still don't want a copy when na_value=np.nan is passed, # and that can be respected because we are already numpy-float - if using_copy_on_write: - assert df.to_numpy(copy=False).base is df.values.base - else: - assert df.to_numpy(copy=False, na_value=np.nan).base is arr + assert df.to_numpy(copy=False).base is df.values.base def test_to_numpy_mixed_dtype_to_str(self): # https://github.com/pandas-dev/pandas/issues/35455 diff --git a/pandas/tests/frame/methods/test_transpose.py b/pandas/tests/frame/methods/test_transpose.py index 45bd8ff0268a8..495663ce135f9 100644 --- a/pandas/tests/frame/methods/test_transpose.py +++ b/pandas/tests/frame/methods/test_transpose.py @@ -124,16 +124,12 @@ def test_transpose_mixed(self): for col, s in mixed_T.items(): assert s.dtype == np.object_ - def test_transpose_get_view(self, float_frame, using_copy_on_write): + def test_transpose_get_view(self, float_frame): dft = float_frame.T dft.iloc[:, 5:10] = 5 + assert (float_frame.values[5:10] != 5).all() - if using_copy_on_write: - assert (float_frame.values[5:10] != 5).all() - else: - assert (float_frame.values[5:10] == 5).all() - - def test_transpose_get_view_dt64tzget_view(self, using_copy_on_write): + def test_transpose_get_view_dt64tzget_view(self): dti = date_range("2016-01-01", periods=6, tz="US/Pacific") arr = dti._data.reshape(3, 2) df = DataFrame(arr) @@ -143,10 +139,7 @@ def test_transpose_get_view_dt64tzget_view(self, using_copy_on_write): assert result._mgr.nblocks == 1 rtrip = result._mgr.blocks[0].values - if using_copy_on_write: - assert np.shares_memory(df._mgr.blocks[0].values._ndarray, rtrip._ndarray) - else: - assert np.shares_memory(arr._ndarray, rtrip._ndarray) + assert np.shares_memory(df._mgr.blocks[0].values._ndarray, rtrip._ndarray) def test_transpose_not_inferring_dt(self): # GH#51546 diff --git a/pandas/tests/frame/methods/test_update.py b/pandas/tests/frame/methods/test_update.py index 7ff8508c3b799..788c6220b2477 100644 --- a/pandas/tests/frame/methods/test_update.py +++ b/pandas/tests/frame/methods/test_update.py @@ -138,7 +138,7 @@ def test_update_datetime_tz(self): expected = DataFrame([pd.Timestamp("2019", tz="UTC")]) tm.assert_frame_equal(result, expected) - def test_update_datetime_tz_in_place(self, using_copy_on_write): + def test_update_datetime_tz_in_place(self): # https://github.com/pandas-dev/pandas/issues/56227 result = DataFrame([pd.Timestamp("2019", tz="UTC")]) orig = result.copy() @@ -146,12 +146,9 @@ def test_update_datetime_tz_in_place(self, using_copy_on_write): result.update(result + pd.Timedelta(days=1)) expected = DataFrame([pd.Timestamp("2019-01-02", tz="UTC")]) tm.assert_frame_equal(result, expected) - if not using_copy_on_write: - tm.assert_frame_equal(view, expected) - else: - tm.assert_frame_equal(view, orig) + tm.assert_frame_equal(view, orig) - def test_update_with_different_dtype(self, using_copy_on_write): + def test_update_with_different_dtype(self): # GH#3217 df = DataFrame({"a": [1, 3], "b": [np.nan, 2]}) df["c"] = np.nan @@ -167,7 +164,7 @@ def test_update_with_different_dtype(self, using_copy_on_write): ) tm.assert_frame_equal(df, expected) - def test_update_modify_view(self, using_copy_on_write, using_infer_string): + def test_update_modify_view(self, using_infer_string): # GH#47188 df = DataFrame({"A": ["1", np.nan], "B": ["100", np.nan]}) df2 = DataFrame({"A": ["a", "x"], "B": ["100", "200"]}) @@ -176,10 +173,7 @@ def test_update_modify_view(self, using_copy_on_write, using_infer_string): df2.update(df) expected = DataFrame({"A": ["1", "x"], "B": ["100", "200"]}) tm.assert_frame_equal(df2, expected) - if using_copy_on_write or using_infer_string: - tm.assert_frame_equal(result_view, df2_orig) - else: - tm.assert_frame_equal(result_view, expected) + tm.assert_frame_equal(result_view, df2_orig) def test_update_dt_column_with_NaT_create_column(self): # GH#16713 diff --git a/pandas/tests/frame/methods/test_values.py b/pandas/tests/frame/methods/test_values.py index f1230e55f9054..dfece3fc7552b 100644 --- a/pandas/tests/frame/methods/test_values.py +++ b/pandas/tests/frame/methods/test_values.py @@ -13,14 +13,10 @@ class TestDataFrameValues: - def test_values(self, float_frame, using_copy_on_write): - if using_copy_on_write: - with pytest.raises(ValueError, match="read-only"): - float_frame.values[:, 0] = 5.0 - assert (float_frame.values[:, 0] != 5).all() - else: + def test_values(self, float_frame): + with pytest.raises(ValueError, match="read-only"): float_frame.values[:, 0] = 5.0 - assert (float_frame.values[:, 0] == 5).all() + assert (float_frame.values[:, 0] != 5).all() def test_more_values(self, float_string_frame): values = float_string_frame.values @@ -228,34 +224,26 @@ def test_values_lcd(self, mixed_float_frame, mixed_int_frame): class TestPrivateValues: - def test_private_values_dt64tz(self, using_copy_on_write): + def test_private_values_dt64tz(self): dta = date_range("2000", periods=4, tz="US/Central")._data.reshape(-1, 1) df = DataFrame(dta, columns=["A"]) tm.assert_equal(df._values, dta) - if using_copy_on_write: - assert not np.shares_memory(df._values._ndarray, dta._ndarray) - else: - # we have a view - assert np.shares_memory(df._values._ndarray, dta._ndarray) + assert not np.shares_memory(df._values._ndarray, dta._ndarray) # TimedeltaArray tda = dta - dta df2 = df - df tm.assert_equal(df2._values, tda) - def test_private_values_dt64tz_multicol(self, using_copy_on_write): + def test_private_values_dt64tz_multicol(self): dta = date_range("2000", periods=8, tz="US/Central")._data.reshape(-1, 2) df = DataFrame(dta, columns=["A", "B"]) tm.assert_equal(df._values, dta) - if using_copy_on_write: - assert not np.shares_memory(df._values._ndarray, dta._ndarray) - else: - # we have a view - assert np.shares_memory(df._values._ndarray, dta._ndarray) + assert not np.shares_memory(df._values._ndarray, dta._ndarray) # TimedeltaArray tda = dta - dta diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 0112e0093c102..b849baa8cab62 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -325,7 +325,6 @@ def test_set_flags( self, allows_duplicate_labels, frame_or_series, - using_copy_on_write, ): obj = DataFrame({"A": [1, 2]}) key = (0, 0) @@ -354,12 +353,7 @@ def test_set_flags( assert np.may_share_memory(obj["A"].values, result["A"].values) result.iloc[key] = 0 - if using_copy_on_write: - assert obj.iloc[key] == 1 - else: - assert obj.iloc[key] == 0 - # set back to 1 for test below - result.iloc[key] = 1 + assert obj.iloc[key] == 1 # Now we do copy. result = obj.set_flags( diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 4fb0bbafc6879..fc40fd5329118 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2006,7 +2006,7 @@ def test_arith_list_of_arraylike_raise(to_add): to_add + df -def test_inplace_arithmetic_series_update(using_copy_on_write): +def test_inplace_arithmetic_series_update(): # https://github.com/pandas-dev/pandas/issues/36373 df = DataFrame({"A": [1, 2, 3]}) df_orig = df.copy() @@ -2014,14 +2014,8 @@ def test_inplace_arithmetic_series_update(using_copy_on_write): vals = series._values series += 1 - if using_copy_on_write: - assert series._values is not vals - tm.assert_frame_equal(df, df_orig) - else: - assert series._values is vals - - expected = DataFrame({"A": [2, 3, 4]}) - tm.assert_frame_equal(df, expected) + assert series._values is not vals + tm.assert_frame_equal(df, df_orig) def test_arithmetic_multiindex_align(): diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 36013e1ac949f..78365ad4a0004 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -81,25 +81,10 @@ def test_consolidate_inplace(self, float_frame): for letter in range(ord("A"), ord("Z")): float_frame[chr(letter)] = chr(letter) - def test_modify_values(self, float_frame, using_copy_on_write): - if using_copy_on_write: - with pytest.raises(ValueError, match="read-only"): - float_frame.values[5] = 5 - assert (float_frame.values[5] != 5).all() - return - - float_frame.values[5] = 5 - assert (float_frame.values[5] == 5).all() - - # unconsolidated - float_frame["E"] = 7.0 - col = float_frame["E"] - float_frame.values[6] = 6 - # as of 2.0 .values does not consolidate, so subsequent calls to .values - # does not share data - assert not (float_frame.values[6] == 6).all() - - assert (col == 7).all() + def test_modify_values(self, float_frame): + with pytest.raises(ValueError, match="read-only"): + float_frame.values[5] = 5 + assert (float_frame.values[5] != 5).all() def test_boolean_set_uncons(self, float_frame): float_frame["E"] = 7.0 @@ -332,7 +317,7 @@ def test_is_mixed_type(self, float_frame, float_string_frame): assert not float_frame._is_mixed_type assert float_string_frame._is_mixed_type - def test_stale_cached_series_bug_473(self, using_copy_on_write): + def test_stale_cached_series_bug_473(self): # this is chained, but ok with option_context("chained_assignment", None): Y = DataFrame( @@ -347,13 +332,9 @@ def test_stale_cached_series_bug_473(self, using_copy_on_write): repr(Y) Y.sum() Y["g"].sum() - if using_copy_on_write: - assert not pd.isna(Y["g"]["c"]) - else: - assert pd.isna(Y["g"]["c"]) + assert not pd.isna(Y["g"]["c"]) - @pytest.mark.filterwarnings("ignore:Setting a value on a view:FutureWarning") - def test_strange_column_corruption_issue(self, using_copy_on_write): + def test_strange_column_corruption_issue(self): # TODO(wesm): Unclear how exactly this is related to internal matters df = DataFrame(index=[0, 1]) df[0] = np.nan @@ -367,10 +348,7 @@ def test_strange_column_corruption_issue(self, using_copy_on_write): if col not in wasCol: wasCol[col] = 1 df[col] = np.nan - if using_copy_on_write: - df.loc[dt, col] = i - else: - df[col][dt] = i + df.loc[dt, col] = i myid = 100 @@ -408,25 +386,17 @@ def test_add_column_with_pandas_array(self): tm.assert_frame_equal(df, df2) -def test_update_inplace_sets_valid_block_values(using_copy_on_write): +def test_update_inplace_sets_valid_block_values(): # https://github.com/pandas-dev/pandas/issues/33457 df = DataFrame({"a": Series([1, 2, None], dtype="category")}) # inplace update of a single column - if 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"): - df["a"].fillna(1, inplace=True) + with tm.raises_chained_assignment_error(): + df["a"].fillna(1, inplace=True) # check we haven't put a Series into any block.values assert isinstance(df._mgr.blocks[0].values, Categorical) - if not using_copy_on_write: - # smoketest for OP bug from GH#35731 - assert df.isnull().sum().sum() == 0 - def test_nonconsolidated_item_cache_take(): # https://github.com/pandas-dev/pandas/issues/35521 diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 20f147e94c514..2bbb20c842dba 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -287,25 +287,16 @@ def test_constructor_dtype_copy(self): new_df["col1"] = 200.0 assert orig_df["col1"][0] == 1.0 - def test_constructor_dtype_nocast_view_dataframe(self, using_copy_on_write): + def test_constructor_dtype_nocast_view_dataframe(self): df = DataFrame([[1, 2]]) should_be_view = DataFrame(df, dtype=df[0].dtype) - if using_copy_on_write: - should_be_view.iloc[0, 0] = 99 - assert df.values[0, 0] == 1 - else: - should_be_view.iloc[0, 0] = 99 - assert df.values[0, 0] == 99 + should_be_view.iloc[0, 0] = 99 + assert df.values[0, 0] == 1 - def test_constructor_dtype_nocast_view_2d_array(self, using_copy_on_write): + def test_constructor_dtype_nocast_view_2d_array(self): df = DataFrame([[1, 2], [3, 4]], dtype="int64") - if not using_copy_on_write: - should_be_view = DataFrame(df.values, dtype=df[0].dtype) - should_be_view.iloc[0, 0] = 97 - assert df.values[0, 0] == 97 - else: - df2 = DataFrame(df.values, dtype=df[0].dtype) - assert df2._mgr.arrays[0].flags.c_contiguous + df2 = DataFrame(df.values, dtype=df[0].dtype) + assert df2._mgr.arrays[0].flags.c_contiguous @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="conversion copies") def test_1d_object_array_does_not_copy(self): @@ -2127,16 +2118,12 @@ def test_constructor_frame_shallow_copy(self, float_frame): cop.index = np.arange(len(cop)) tm.assert_frame_equal(float_frame, orig) - def test_constructor_ndarray_copy(self, float_frame, using_copy_on_write): + def test_constructor_ndarray_copy(self, float_frame): arr = float_frame.values.copy() df = DataFrame(arr) arr[5] = 5 - if using_copy_on_write: - assert not (df.values[5] == 5).all() - else: - assert (df.values[5] == 5).all() - + assert not (df.values[5] == 5).all() df = DataFrame(arr, copy=True) arr[6] = 6 assert not (df.values[6] == 6).all() @@ -2473,7 +2460,6 @@ def test_dict_nocopy( copy, any_numeric_ea_dtype, any_numpy_dtype, - using_copy_on_write, ): a = np.array([1, 2], dtype=any_numpy_dtype) b = np.array([3, 4], dtype=any_numpy_dtype) @@ -2541,9 +2527,6 @@ def check_views(c_only: bool = False): # view, so we have to check in the other direction df.iloc[:, 2] = pd.array([45, 46], dtype=c.dtype) assert df.dtypes.iloc[2] == c.dtype - if not copy and not using_copy_on_write: - check_views(True) - if copy: if a.dtype.kind == "M": assert a[0] == a.dtype.type(1, "ns") @@ -2553,12 +2536,6 @@ def check_views(c_only: bool = False): assert b[0] == b.dtype.type(3) # FIXME(GH#35417): enable after GH#35417 assert c[0] == c_orig[0] # i.e. df.iloc[0, 2]=45 did *not* update c - elif not using_copy_on_write: - # TODO: we can call check_views if we stop consolidating - # in setitem_with_indexer - assert c[0] == 45 # i.e. df.iloc[0, 2]=45 *did* update c - # TODO: we can check b[0] == 0 if we stop consolidating in - # setitem_with_indexer (except for datetimelike?) def test_construct_from_dict_ea_series(self): # GH#53744 - default of copy=True should also apply for Series with