diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 4742348b209d9..e69b0899facb9 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -796,7 +796,7 @@ def _gen_unique_rand(rng, _extra_size): def makeMissingDataframe(density: float = 0.9, random_state=None) -> DataFrame: df = makeDataFrame() i, j = _create_missing_idx(*df.shape, density=density, random_state=random_state) - df.values[i, j] = np.nan + df.iloc[i, j] = np.nan return df diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 4bb7f62fb13bd..2dfc31ccc1638 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -620,7 +620,7 @@ def test_setitem_fancy_scalar(self, float_frame): for idx in f.index[::5]: i = f.index.get_loc(idx) val = np.random.randn() - expected.values[i, j] = val + expected.iloc[i, j] = val ix[idx, col] = val tm.assert_frame_equal(f, expected) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 5082aea354d6d..c4f5b60918e84 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -218,9 +218,8 @@ def test_corr_item_cache(self, using_copy_on_write): _ = df.corr(numeric_only=True) if using_copy_on_write: - # TODO(CoW) we should disallow this, so `df` doesn't get updated - ser.values[0] = 99 - assert df.loc[0, "A"] == 99 + 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 diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index b3f63db05dd28..2b5d675f029d3 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -550,8 +550,9 @@ def test_fillna_dataframe(self): tm.assert_frame_equal(result, expected) def test_fillna_columns(self): - df = DataFrame(np.random.randn(10, 10)) - df.values[:, ::2] = np.nan + arr = np.random.randn(10, 10) + arr[:, ::2] = np.nan + df = DataFrame(arr) result = df.fillna(method="ffill", axis=1) expected = df.T.fillna(method="pad").T diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c621e9bae78f8..a13252ffdcf79 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2102,13 +2102,14 @@ def test_constructor_frame_copy(self, float_frame): def test_constructor_ndarray_copy(self, float_frame, using_array_manager): if not using_array_manager: - df = DataFrame(float_frame.values) + arr = float_frame.values.copy() + df = DataFrame(arr) - float_frame.values[5] = 5 + arr[5] = 5 assert (df.values[5] == 5).all() - df = DataFrame(float_frame.values, copy=True) - float_frame.values[6] = 6 + df = DataFrame(arr, copy=True) + arr[6] = 6 assert not (df.values[6] == 6).all() else: arr = float_frame.values.copy() diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index e93dd022f46ac..0942e5320de39 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -356,8 +356,9 @@ def test_cython_api2(): def test_cython_median(): - df = DataFrame(np.random.randn(1000)) - df.values[::2] = np.nan + arr = np.random.randn(1000) + arr[::2] = np.nan + df = DataFrame(arr) labels = np.random.randint(0, 50, size=1000).astype(float) labels[::17] = np.nan diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py index dd16cca28677c..96d631964ab65 100644 --- a/pandas/tests/indexing/multiindex/test_slice.py +++ b/pandas/tests/indexing/multiindex/test_slice.py @@ -750,7 +750,7 @@ def test_int_series_slicing(self, multiindex_year_month_day_dataframe_random_dat exp = ymd["A"].copy() s[5:] = 0 - exp.values[5:] = 0 + exp.iloc[5:] = 0 tm.assert_numpy_array_equal(s.values, exp.values) result = ymd[5:] diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index ab84e0781a8f5..4bb00ad7f4c81 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -372,8 +372,8 @@ def test_frame(compression, setup_path): df = tm.makeDataFrame() # put in some random NAs - df.values[0, 0] = np.nan - df.values[5, 3] = np.nan + df.iloc[0, 0] = np.nan + df.iloc[5, 3] = np.nan _check_roundtrip_table( df, tm.assert_frame_equal, path=setup_path, compression=compression diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index 3d09954ed3c0f..c36831ba60b89 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -899,7 +899,7 @@ def expected(self, dtype): arr = np.arange(5).astype(dtype) ser = Series(arr) ser = ser.astype(object) - ser.values[0] = np.timedelta64(4, "ns") + ser.iloc[0] = np.timedelta64(4, "ns") return ser @pytest.fixture diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index f8144a732e3a9..8897a0936b2c7 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -32,7 +32,7 @@ def test_fillna_nat(self): filled2 = series.fillna(value=series.values[2]) expected = series.copy() - expected.values[3] = expected.values[2] + expected.iloc[3] = expected.iloc[2] tm.assert_series_equal(filled, expected) tm.assert_series_equal(filled2, expected)