Skip to content

made changes to resolve unsupported-assignment-operation from #48855 #48982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions asv_bench/benchmarks/join_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ def setup(self, direction, tolerance):
df1 = df1.sort_values("time")
df2 = df2.sort_values("time")

df1["time32"] = np.int32(df1.time)
df2["time32"] = np.int32(df2.time)
df1.loc[:, "time32"] = np.int32(df1.time)
df2.loc[:, "time32"] = np.int32(df2.time)

df1["timeu64"] = np.uint64(df1.time)
df2["timeu64"] = np.uint64(df2.time)
df1.loc[:, "timeu64"] = np.uint64(df1.time)
df2.loc[:, "timeu64"] = np.uint64(df2.time)

self.df1a = df1[["time", "value1"]]
self.df2a = df2[["time", "value2"]]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/categorical/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_setitem_listlike(self):
np.random.randint(0, 5, size=150000).astype(np.int8)
).add_categories([-1000])
indexer = np.array([100000]).astype(np.int64)
cat[indexer] = -1000
cat.loc[indexer] = -1000

# we are asserting the code result here
# which maps to the -1000 category
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/categorical/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_numeric_like_ops(self):
cat_labels = Categorical(labels, labels)

df = df.sort_values(by=["value"], ascending=True)
df["value_group"] = pd.cut(
df.loc[:, "value_group"] = pd.cut(
df.value, range(0, 10500, 500), right=False, labels=cat_labels
)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def test_setitem_with_expansion_categorical_dtype(self):
cat = ser.values

# setting with a Categorical
df["D"] = cat
df.loc[:, "D"] = cat
str(df)

result = df.dtypes
Expand All @@ -854,7 +854,7 @@ def test_setitem_with_expansion_categorical_dtype(self):
tm.assert_series_equal(result, expected)

# setting with a Series
df["E"] = ser
df.loc[: "E"] = ser
str(df)

result = df.dtypes
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_describe_categorical(self):
cat_labels = Categorical(labels, labels)

df = df.sort_values(by=["value"], ascending=True)
df["value_group"] = pd.cut(
df.loc[:,"value_group"] = pd.cut(
df.value, range(0, 10500, 500), right=False, labels=cat_labels
)
cat = df
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/frame/test_stack_unstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def test_unstack_dtypes(self):

# mixed
df2 = df.set_index(["A", "B"])
df2["C"] = 3.0
df2.loc[:, "C"] = 3.0
df3 = df2.unstack("B")
result = df3.dtypes
expected = Series(
Expand All @@ -594,7 +594,7 @@ def test_unstack_dtypes(self):
),
)
tm.assert_series_equal(result, expected)
df2["D"] = "foo"
df2.loc[:, "D"] = "foo"
df3 = df2.unstack("B")
result = df3.dtypes
expected = Series(
Expand Down Expand Up @@ -626,7 +626,7 @@ def test_unstack_dtypes_mixed_date(self, c, d):
right = df.iloc[:3].copy(deep=True)

df = df.set_index(["A", "B"])
df["D"] = df["D"].astype("int64")
df.loc[:, "D"] = df["D"].astype("int64")

left = df.iloc[:3].unstack(0)
right = right.set_index(["A", "B"]).unstack(0)
Expand Down Expand Up @@ -2007,7 +2007,7 @@ def test_unstack_with_missing_int_cast_to_float(self, using_array_manager):
).set_index(["a", "b"])

# add another int column to get 2 blocks
df["is_"] = 1
df.loc[:, "is_"] = 1
if not using_array_manager:
assert len(df._mgr.blocks) == 2

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def test_sort():
cat_labels = Categorical(labels, labels)

df = df.sort_values(by=["value"], ascending=True)
df["value_group"] = pd.cut(
df.loc[:, "value_group"] = pd.cut(
df.value, range(0, 10500, 500), right=False, labels=cat_labels
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_nth.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_nth():
tm.assert_frame_equal(g.nth(0, dropna="any"), exp.iloc[[1, 2]])
tm.assert_frame_equal(g.nth(-1, dropna="any"), exp.iloc[[1, 2]])

exp["B"] = np.nan
exp.loc[:, "B"] = np.nan
tm.assert_frame_equal(g.nth(7, dropna="any"), exp.iloc[[1, 2]])
tm.assert_frame_equal(g.nth(2, dropna="any"), exp.iloc[[1, 2]])

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_series_groupby_value_counts_with_grouper():
}
).drop([3])

df["Datetime"] = to_datetime(df["Timestamp"].apply(lambda t: str(t)), unit="s")
df.loc[:, "Datetime"] = to_datetime(df["Timestamp"].apply(lambda t: str(t)), unit="s")
dfg = df.groupby(Grouper(freq="1D", key="Datetime"))

# have to sort on index because of unstable sort on values xref GH9212
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/indexing/multiindex/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,25 @@ def test_frame_getitem_nan_multiindex(nulls_fixture):
[[11, n, 13], [21, n, 23], [31, n, 33], [41, n, 43]],
columns=cols,
).set_index(["a", "b"])
df["c"] = df["c"].astype("int64")
df.loc[:, "c"] = df["c"].astype("int64")

idx = (21, n)
result = df.loc[:idx]
expected = DataFrame([[11, n, 13], [21, n, 23]], columns=cols).set_index(["a", "b"])
expected["c"] = expected["c"].astype("int64")
expected.loc[:, "c"] = expected["c"].astype("int64")
tm.assert_frame_equal(result, expected)

result = df.loc[idx:]
expected = DataFrame(
[[21, n, 23], [31, n, 33], [41, n, 43]], columns=cols
).set_index(["a", "b"])
expected["c"] = expected["c"].astype("int64")
expected.loc[:, "c"] = expected["c"].astype("int64")
tm.assert_frame_equal(result, expected)

idx1, idx2 = (21, n), (31, n)
result = df.loc[idx1:idx2]
expected = DataFrame([[21, n, 23], [31, n, 33]], columns=cols).set_index(["a", "b"])
expected["c"] = expected["c"].astype("int64")
expected.loc[:, "c"] = expected["c"].astype("int64")
tm.assert_frame_equal(result, expected)


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/multiindex/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_iloc_setitem_int_multiindex_series(data, indexes, values, expected_k):
for i, v in zip(indexes, values):
series.iloc[i] += v

df["k"] = expected_k
df.loc[:, "k"] = expected_k
expected = df.k
tm.assert_series_equal(series, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def test_detect_chained_assignment_is_copy(self):
# an identical take, so no copy
df = DataFrame({"a": [1]}).dropna()
assert df._is_copy is None
df["a"] += 1
df.loc[:, "a"] += 1

@pytest.mark.arm_slow
def test_detect_chained_assignment_sorting(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def test_record_prefix(self, state_data):
expected.extend(rec["counties"])
expected = DataFrame(expected)
expected = expected.rename(columns=lambda x: "county_" + x)
expected["state"] = np.array(["Florida", "Ohio"]).repeat([3, 2])
expected.loc[:, "state"] = np.array(["Florida", "Ohio"]).repeat([3, 2])

tm.assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def test_append_with_timedelta(setup_path):
def test_append_to_multiple(setup_path):
df1 = tm.makeTimeDataFrame()
df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format)
df2["foo"] = "bar"
df2.loc[:, "foo"] = "bar"
df = concat([df1, df2], axis=1)

with ensure_clean_store(setup_path) as store:
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/pytables/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def test_select_iterator(setup_path):
df1 = tm.makeTimeDataFrame(500)
store.append("df1", df1, data_columns=True)
df2 = tm.makeTimeDataFrame(500).rename(columns="{}_2".format)
df2["foo"] = "bar"
df2.loc[:, "foo"] = "bar"
store.append("df2", df2)

df = concat([df1, df2], axis=1)
Expand Down Expand Up @@ -790,7 +790,7 @@ def test_select_as_multiple(setup_path):

df1 = tm.makeTimeDataFrame()
df2 = tm.makeTimeDataFrame().rename(columns="{}_2".format)
df2["foo"] = "bar"
df2.loc[:, "foo"] = "bar"

with ensure_clean_store(setup_path) as store:

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_idxmin(self):
string_series = tm.makeStringSeries().rename("series")

# add some NaNs
string_series[5:15] = np.NaN
string_series.iloc[5:15] = np.NaN

# skipna or no
assert string_series[string_series.idxmin()] == string_series.min()
Expand Down Expand Up @@ -875,7 +875,7 @@ def test_idxmax(self):
string_series = tm.makeStringSeries().rename("series")

# add some NaNs
string_series[5:15] = np.NaN
string_series.iloc[5:15] = np.NaN

# skipna or no
assert string_series[string_series.idxmax()] == string_series.max()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_resampler_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def test_resample_empty_Dataframe(keys):
df = df.set_index("date")
result = df.groupby(keys).resample(rule=pd.to_timedelta("00:00:01")).mean()
expected = DataFrame(columns=["a", "b", "date"]).set_index(keys, drop=False)
expected["date"] = pd.to_datetime(expected["date"])
expected.loc[:, "date"] = pd.to_datetime(expected["date"])
expected = expected.set_index("date", append=True, drop=True)
if len(keys) == 1:
expected.index.name = keys[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reshape/test_get_dummies.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_dataframe_dummies_drop_first_with_na(self, df, sparse):
expected = expected.sort_index(axis=1)
if sparse:
for col in cols:
expected[col] = SparseArray(expected[col])
expected.loc[:, col] = SparseArray(expected[col])

tm.assert_frame_equal(result, expected)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def test_margins_dtype(self):
expected = DataFrame(
{"dull": [12, 21, 3, 9, 45], "shiny": [33, 0, 36, 51, 120]}, index=mi
).rename_axis("C", axis=1)
expected["All"] = expected["dull"] + expected["shiny"]
expected.loc[:, "All"] = expected["dull"] + expected["shiny"]

result = df.pivot_table(
values="D",
Expand All @@ -1012,7 +1012,7 @@ def test_margins_dtype_len(self):
expected = DataFrame(
{"dull": [1, 1, 2, 1, 5], "shiny": [2, 0, 2, 2, 6]}, index=mi
).rename_axis("C", axis=1)
expected["All"] = expected["dull"] + expected["shiny"]
expected.loc[:, "All"] = expected["dull"] + expected["shiny"]

result = self.data.pivot_table(
values="D",
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_basic_indexing():
s[5]
msg = r"index 5 is out of bounds for axis (0|1) with size 5|^5$"
with pytest.raises(IndexError, match=msg):
s[5] = 0
s.loc[5] = 0


def test_basic_getitem_with_labels(datetime_series):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_timedelta_fillna(self, frame_or_series):
obj = frame_or_series(td)
result = obj.ffill()
expected = td.fillna(Timedelta(seconds=0))
expected[0] = np.nan
expected.loc[:, 0] = np.nan
expected = frame_or_series(expected)

tm.assert_equal(result, expected)
Expand All @@ -322,7 +322,7 @@ def test_timedelta_fillna(self, frame_or_series):
obj = frame_or_series(td)
result = obj.bfill()
expected = td.fillna(Timedelta(seconds=0))
expected[2] = timedelta(days=1, seconds=9 * 3600 + 60 + 1)
expected.loc[:, 2] = timedelta(days=1, seconds=9 * 3600 + 60 + 1)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/window/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def test_groupby_rolling_string_index(self):
).set_index("index")

groups = df.groupby("group")
df["count_to_date"] = groups.cumcount()
df.loc[:, "count_to_date"] = groups.cumcount()
rolling_groups = groups.rolling("10d", on="eventTime")
result = rolling_groups.apply(lambda df: df.shape[0])
expected = DataFrame(
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exclude = '''

[tool.pylint.messages_control]
max-line-length = 88
#"unsupported-assignment-operation",
disable = [
"C",
"R",
Expand All @@ -57,7 +58,7 @@ disable = [
"unexpected-keyword-arg",
"unpacking-non-sequence",
"unsubscriptable-object",
"unsupported-assignment-operation",

"unsupported-membership-test",
"used-before-assignment",
]
Expand Down