diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index daddca7891b93..47ebca0b9bf5c 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -66,7 +66,7 @@ def test_combine_first(self, float_frame): assert (combined["A"][:10] == 1).all() # reverse overlap - tail["A"][:10] = 0 + tail.iloc[:10, tail.columns.get_loc("A")] = 0 combined = tail.combine_first(head) assert (combined["A"][:10] == 0).all() diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index 2f0a4195d2f74..ee9af3f436943 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -27,8 +27,8 @@ def test_cov(self, float_frame, float_string_frame): # with NAs frame = float_frame.copy() - frame["A"][:5] = np.nan - frame["B"][5:10] = np.nan + frame.iloc[:5, frame.columns.get_loc("A")] = np.nan + frame.iloc[5:10, frame.columns.get_loc("B")] = np.nan result = frame.cov(min_periods=len(frame) - 8) expected = frame.cov() expected.loc["A", "B"] = np.nan diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 7c33242192d2e..3e22734992d23 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -1333,7 +1333,8 @@ def test_combineFrame(self, float_frame, mixed_float_frame, mixed_int_frame): frame_copy = float_frame.reindex(float_frame.index[::2]) del frame_copy["D"] - frame_copy["C"][:5] = np.nan + # adding NAs to first 5 values of column "C" + frame_copy.loc[: frame_copy.index[4], "C"] = np.nan added = float_frame + frame_copy diff --git a/pandas/tests/groupby/test_apply_mutate.py b/pandas/tests/groupby/test_apply_mutate.py index 36e117cf03353..d1f25aabe31a2 100644 --- a/pandas/tests/groupby/test_apply_mutate.py +++ b/pandas/tests/groupby/test_apply_mutate.py @@ -72,7 +72,7 @@ def test_apply_function_with_indexing(): ) def fn(x): - x.col2[x.index[-1]] = 0 + x.loc[x.index[-1], "col2"] = 0 return x.col2 result = df.groupby(["col1"], as_index=False).apply(fn) diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index 9d5e65e692fdc..a57b363c0a448 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -128,7 +128,7 @@ def test_partial_set(self, multiindex_year_month_day_dataframe_random_data): df = ymd.copy() exp = ymd.copy() df.loc[2000, 4] = 0 - exp.loc[2000, 4].values[:] = 0 + exp.iloc[65:85] = 0 tm.assert_frame_equal(df, exp) df["A"].loc[2000, 4] = 1 @@ -136,7 +136,7 @@ def test_partial_set(self, multiindex_year_month_day_dataframe_random_data): tm.assert_frame_equal(df, exp) df.loc[2000] = 5 - exp.loc[2000].values[:] = 5 + exp.iloc[:100] = 5 tm.assert_frame_equal(df, exp) # this works...for now diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 3f8e4401808b7..1cd96bff4177d 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -53,7 +53,7 @@ def test_not_change_nan_loc(series, new_series, expected_ser): # GH 28403 df = DataFrame({"A": series}) - df["A"].loc[:] = new_series + df.loc[:, "A"] = new_series expected = DataFrame({"A": expected_ser}) tm.assert_frame_equal(df.isna(), expected) tm.assert_frame_equal(df.notna(), ~expected)