Skip to content

STYLE: fix some consider-using-enumerate pylint warnings #49214

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

Merged
merged 5 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 2 additions & 4 deletions pandas/core/array_algos/take.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,11 @@ def _take_2d_multi_object(
out[row_mask, :] = fill_value
if col_needs:
out[:, col_mask] = fill_value
for i in range(len(row_idx)):
for i, u_ in enumerate(row_idx):
u_ = row_idx[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This u_ shouldn' be needed anymore I think


if u_ != -1:
for j in range(len(col_idx)):
v = col_idx[j]

for j, v in enumerate(col_idx):
if v != -1:
out[i, j] = arr[u_, v]

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,11 +1438,11 @@ def __array__(self, dtype: NpDtype | None = None) -> np.ndarray:
closed = self.closed

result = np.empty(len(left), dtype=object)
for i in range(len(left)):
for i, left_value in enumerate(left):
if mask[i]:
result[i] = np.nan
else:
result[i] = Interval(left[i], right[i], closed)
result[i] = Interval(left_value, right[i], closed)
return result

def __arrow_array__(self, type=None):
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/formats/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,17 @@ def best_len(values: list[str]) -> int:
summary = ""
line = space2

for max_items in range(len(head)):
word = head[max_items] + sep + " "
for head_value in head:
word = head_value + sep + " "
summary, line = _extend_line(summary, line, word, display_width, space2)

if is_truncated:
# remove trailing space of last line
summary += line.rstrip() + space2 + "..."
line = space2

for max_items in range(len(tail) - 1):
word = tail[max_items] + sep + " "
for tail_item in tail[:-1]:
word = tail_item + sep + " "
summary, line = _extend_line(summary, line, word, display_width, space2)

# last value: no sep added + 1 space of width used for trailing ','
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/sparse/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class TestGetitem:
def test_getitem(self):
dense = arr.to_dense()
for i in range(len(arr)):
tm.assert_almost_equal(arr[i], dense[i])
for i, value in enumerate(arr):
tm.assert_almost_equal(value, dense[i])
tm.assert_almost_equal(arr[-i], dense[-i])

def test_getitem_arraylike_mask(self):
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/frame/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ def test_replace_input_formats_listlike(self):
values = [-2, -1, "missing"]
result = df.replace(to_rep, values)
expected = df.copy()
for i in range(len(to_rep)):
return_value = expected.replace(to_rep[i], values[i], inplace=True)
for rep, value in zip(to_rep, values):
return_value = expected.replace(rep, value, inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

Expand All @@ -901,8 +901,8 @@ def test_replace_input_formats_scalar(self):
to_rep = [np.nan, 0, ""]
result = df.replace(to_rep, -1)
expected = df.copy()
for i in range(len(to_rep)):
return_value = expected.replace(to_rep[i], -1, inplace=True)
for rep in to_rep:
return_value = expected.replace(rep, -1, inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/multi/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,9 @@ def test_pyint_engine():
# keys would collide; if truncating the last levels, the fifth and
# sixth; if rotating bits rather than shifting, the third and fifth.

for idx in range(len(keys)):
for idx, key_value in enumerate(keys):
index = MultiIndex.from_tuples(keys)
assert index.get_loc(keys[idx]) == idx
assert index.get_loc(key_value) == idx

expected = np.arange(idx + 1, dtype=np.intp)
result = index.get_indexer([keys[i] for i in expected])
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,15 @@ def test_big_dates(self, datapath):
mm = [0, 0, 59, 0, 0, 0]
ss = [0, 0, 59, 0, 0, 0]
expected = []
for i in range(len(yr)):
for year, month, day, hour, minute, second in zip(yr, mo, dd, hr, mm, ss):
row = []
for j in range(7):
if j == 0:
row.append(datetime(yr[i], mo[i], dd[i], hr[i], mm[i], ss[i]))
row.append(datetime(year, month, day, hour, minute, second))
elif j == 6:
row.append(datetime(yr[i], 1, 1))
row.append(datetime(year, 1, 1))
else:
row.append(datetime(yr[i], mo[i], dd[i]))
row.append(datetime(year, month, day))
expected.append(row)
expected.append([pd.NaT] * 7)
columns = [
Expand Down