Skip to content

Commit 04e01a1

Browse files
TST: avoid chained assignment in tests outside of specific tests on chaining (#46980)
1 parent c40f438 commit 04e01a1

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

pandas/tests/frame/methods/test_combine_first.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_combine_first(self, float_frame):
6666
assert (combined["A"][:10] == 1).all()
6767

6868
# reverse overlap
69-
tail["A"][:10] = 0
69+
tail.iloc[:10, tail.columns.get_loc("A")] = 0
7070
combined = tail.combine_first(head)
7171
assert (combined["A"][:10] == 0).all()
7272

pandas/tests/frame/methods/test_cov_corr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_cov(self, float_frame, float_string_frame):
2727

2828
# with NAs
2929
frame = float_frame.copy()
30-
frame["A"][:5] = np.nan
31-
frame["B"][5:10] = np.nan
30+
frame.iloc[:5, frame.columns.get_loc("A")] = np.nan
31+
frame.iloc[5:10, frame.columns.get_loc("B")] = np.nan
3232
result = frame.cov(min_periods=len(frame) - 8)
3333
expected = frame.cov()
3434
expected.loc["A", "B"] = np.nan

pandas/tests/frame/test_arithmetic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,8 @@ def test_combineFrame(self, float_frame, mixed_float_frame, mixed_int_frame):
13331333
frame_copy = float_frame.reindex(float_frame.index[::2])
13341334

13351335
del frame_copy["D"]
1336-
frame_copy["C"][:5] = np.nan
1336+
# adding NAs to first 5 values of column "C"
1337+
frame_copy.loc[: frame_copy.index[4], "C"] = np.nan
13371338

13381339
added = float_frame + frame_copy
13391340

pandas/tests/groupby/test_apply_mutate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_apply_function_with_indexing():
7272
)
7373

7474
def fn(x):
75-
x.col2[x.index[-1]] = 0
75+
x.loc[x.index[-1], "col2"] = 0
7676
return x.col2
7777

7878
result = df.groupby(["col1"], as_index=False).apply(fn)

pandas/tests/indexing/multiindex/test_partial.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def test_partial_set(self, multiindex_year_month_day_dataframe_random_data):
128128
df = ymd.copy()
129129
exp = ymd.copy()
130130
df.loc[2000, 4] = 0
131-
exp.loc[2000, 4].values[:] = 0
131+
exp.iloc[65:85] = 0
132132
tm.assert_frame_equal(df, exp)
133133

134134
df["A"].loc[2000, 4] = 1
135135
exp["A"].loc[2000, 4].values[:] = 1
136136
tm.assert_frame_equal(df, exp)
137137

138138
df.loc[2000] = 5
139-
exp.loc[2000].values[:] = 5
139+
exp.iloc[:100] = 5
140140
tm.assert_frame_equal(df, exp)
141141

142142
# this works...for now

pandas/tests/indexing/test_loc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
def test_not_change_nan_loc(series, new_series, expected_ser):
5454
# GH 28403
5555
df = DataFrame({"A": series})
56-
df["A"].loc[:] = new_series
56+
df.loc[:, "A"] = new_series
5757
expected = DataFrame({"A": expected_ser})
5858
tm.assert_frame_equal(df.isna(), expected)
5959
tm.assert_frame_equal(df.notna(), ~expected)

0 commit comments

Comments
 (0)