Skip to content

CLN: fix E741 ambiguous variable #34150 #38009

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
Nov 24, 2020
Merged
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
5 changes: 4 additions & 1 deletion asv_bench/benchmarks/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def setup(self):
nidvars = 20
N = 5000
self.letters = list("ABCD")
yrvars = [l + str(num) for l, num in product(self.letters, range(1, nyrs + 1))]
yrvars = [
letter + str(num)
for letter, num in product(self.letters, range(1, nyrs + 1))
]
columns = [str(i) for i in range(nidvars)] + yrvars
self.df = DataFrame(np.random.randn(N, nidvars + len(yrvars)), columns=columns)
self.df["id"] = self.df.index
Expand Down
16 changes: 8 additions & 8 deletions pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,19 +749,19 @@ def assert_index_equal(
"""
__tracebackhide__ = True

def _check_types(l, r, obj="Index"):
def _check_types(left, right, obj="Index"):
if exact:
assert_class_equal(l, r, exact=exact, obj=obj)
assert_class_equal(left, right, exact=exact, obj=obj)

# Skip exact dtype checking when `check_categorical` is False
if check_categorical:
assert_attr_equal("dtype", l, r, obj=obj)
assert_attr_equal("dtype", left, right, obj=obj)

# allow string-like to have different inferred_types
if l.inferred_type in ("string"):
assert r.inferred_type in ("string")
if left.inferred_type in ("string"):
assert right.inferred_type in ("string")
else:
assert_attr_equal("inferred_type", l, r, obj=obj)
assert_attr_equal("inferred_type", left, right, obj=obj)

def _get_ilevel_values(index, level):
# accept level number only
Expand Down Expand Up @@ -1147,9 +1147,9 @@ def _raise(left, right, err_msg):
)

diff = 0
for l, r in zip(left, right):
for left_arr, right_arr in zip(left, right):
# count up differences
if not array_equivalent(l, r, strict_nan=strict_nan):
if not array_equivalent(left_arr, right_arr, strict_nan=strict_nan):
diff += 1

diff = diff * 100.0 / left.size
Expand Down
25 changes: 14 additions & 11 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class SettingWithCopyWarning(Warning):
pass


def flatten(l):
def flatten(line):
"""
Flatten an arbitrarily nested sequence.

Parameters
----------
l : sequence
line : sequence
The non string sequence to flatten

Notes
Expand All @@ -59,11 +59,11 @@ def flatten(l):
-------
flattened : generator
"""
for el in l:
if iterable_not_string(el):
yield from flatten(el)
for element in line:
if iterable_not_string(element):
yield from flatten(element)
else:
yield el
yield element


def consensus_name_attr(objs):
Expand Down Expand Up @@ -282,20 +282,23 @@ def is_null_slice(obj) -> bool:
)


def is_true_slices(l):
def is_true_slices(line):
"""
Find non-trivial slices in "l": return a list of booleans with same length.
Find non-trivial slices in "line": return a list of booleans with same length.
"""
return [isinstance(k, slice) and not is_null_slice(k) for k in l]
return [isinstance(k, slice) and not is_null_slice(k) for k in line]


# TODO: used only once in indexing; belongs elsewhere?
def is_full_slice(obj, l) -> bool:
def is_full_slice(obj, line) -> bool:
"""
We have a full length slice.
"""
return (
isinstance(obj, slice) and obj.start == 0 and obj.stop == l and obj.step is None
isinstance(obj, slice)
and obj.start == 0
and obj.stop == line
and obj.step is None
)


Expand Down
6 changes: 3 additions & 3 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
from pandas.core.construction import array


def _get_dtype_kinds(l) -> Set[str]:
def _get_dtype_kinds(arrays) -> Set[str]:
"""
Parameters
----------
l : list of arrays
arrays : list of arrays

Returns
-------
set[str]
A set of kinds that exist in this list of arrays.
"""
typs: Set[str] = set()
for arr in l:
for arr in arrays:
# Note: we use dtype.kind checks because they are much more performant
# than is_foo_dtype

Expand Down
9 changes: 6 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def _repr_fits_horizontal_(self, ignore_width: bool = False) -> bool:

d.to_string(buf=buf)
value = buf.getvalue()
repr_width = max(len(l) for l in value.split("\n"))
repr_width = max(len(line) for line in value.split("\n"))

return repr_width < width

Expand Down Expand Up @@ -5962,13 +5962,16 @@ def _dispatch_frame_op(self, right, func, axis: Optional[int] = None):
# maybe_align_as_frame ensures we do not have an ndarray here
assert not isinstance(right, np.ndarray)

arrays = [array_op(l, r) for l, r in zip(self._iter_column_arrays(), right)]
arrays = [
array_op(_left, _right)
for _left, _right in zip(self._iter_column_arrays(), right)
]

elif isinstance(right, Series):
assert right.index.equals(self.index) # Handle other cases later
right = right._values

arrays = [array_op(l, right) for l in self._iter_column_arrays()]
arrays = [array_op(left, right) for left in self._iter_column_arrays()]

else:
# Remaining cases have less-obvious dispatch rules
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def set_codes(self, codes, level=None, inplace=None, verify_integrity=True):
def _engine(self):
# Calculate the number of bits needed to represent labels in each
# level, as log2 of their sizes (including -1 for NaN):
sizes = np.ceil(np.log2([len(l) + 1 for l in self.levels]))
sizes = np.ceil(np.log2([len(level) + 1 for level in self.levels]))

# Sum bit counts, starting from the _right_....
lev_bits = np.cumsum(sizes[::-1])[::-1]
Expand Down Expand Up @@ -1217,10 +1217,10 @@ def dtype(self) -> np.dtype:
def _is_memory_usage_qualified(self) -> bool:
""" return a boolean if we need a qualified .info display """

def f(l):
return "mixed" in l or "string" in l or "unicode" in l
def f(level):
return "mixed" in level or "string" in level or "unicode" in level

return any(f(l) for l in self._inferred_type_levels)
return any(f(level) for level in self._inferred_type_levels)

@doc(Index.memory_usage)
def memory_usage(self, deep: bool = False) -> int:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _indexer_and_to_sort(self):
@cache_readonly
def sorted_labels(self):
indexer, to_sort = self._indexer_and_to_sort
return [l.take(indexer) for l in to_sort]
return [line.take(indexer) for line in to_sort]

def _make_sorted_values(self, values: np.ndarray) -> np.ndarray:
indexer, _ = self._indexer_and_to_sort
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def _get_formatted_column_labels(self, frame: "DataFrame") -> List[List[str]]:
dtypes = self.frame.dtypes._values

# if we have a Float level, they don't use leading space at all
restrict_formatting = any(l.is_floating for l in columns.levels)
restrict_formatting = any(level.is_floating for level in columns.levels)
need_leadsp = dict(zip(fmt_columns, map(is_numeric_dtype, dtypes)))

def space_format(x, y):
Expand Down
18 changes: 9 additions & 9 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,9 +2974,9 @@ def _check_comments(self, lines):
if self.comment is None:
return lines
ret = []
for l in lines:
for line in lines:
rl = []
for x in l:
for x in line:
if not isinstance(x, str) or self.comment not in x:
rl.append(x)
else:
Expand All @@ -3003,14 +3003,14 @@ def _remove_empty_lines(self, lines):
The same array of lines with the "empty" ones removed.
"""
ret = []
for l in lines:
for line in lines:
# Remove empty lines and lines with only one whitespace value
if (
len(l) > 1
or len(l) == 1
and (not isinstance(l[0], str) or l[0].strip())
len(line) > 1
or len(line) == 1
and (not isinstance(line[0], str) or line[0].strip())
):
ret.append(l)
ret.append(line)
return ret

def _check_thousands(self, lines):
Expand All @@ -3023,9 +3023,9 @@ def _check_thousands(self, lines):

def _search_replace_num_columns(self, lines, search, replace):
ret = []
for l in lines:
for line in lines:
rl = []
for i, x in enumerate(l):
for i, x in enumerate(line):
if (
not isinstance(x, str)
or search not in x
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4689,7 +4689,7 @@ def read(

# remove names for 'level_%d'
df.index = df.index.set_names(
[None if self._re_levels.search(l) else l for l in df.index.names]
[None if self._re_levels.search(name) else name for name in df.index.names]
)

return df
Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def _make_plot(self):
self.maybe_color_bp(bp)
self._return_obj = ret

labels = [l for l, _ in self._iter_data()]
labels = [pprint_thing(l) for l in labels]
labels = [left for left, _ in self._iter_data()]
labels = [pprint_thing(left) for left in labels]
if not self.use_index:
labels = [pprint_thing(key) for key in range(len(labels))]
self._set_ticklabels(ax, labels)
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ def blank_labeler(label, value):
# Blank out labels for values of 0 so they don't overlap
# with nonzero wedges
if labels is not None:
blabels = [blank_labeler(l, value) for l, value in zip(labels, y)]
blabels = [blank_labeler(left, value) for left, value in zip(labels, y)]
else:
# pandas\plotting\_matplotlib\core.py:1546: error: Incompatible
# types in assignment (expression has type "None", variable has
Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def get_all_lines(ax: "Axes") -> List["Line2D"]:

def get_xlim(lines: Iterable["Line2D"]) -> Tuple[float, float]:
left, right = np.inf, -np.inf
for l in lines:
x = l.get_xdata(orig=False)
for line in lines:
x = line.get_xdata(orig=False)
left = min(np.nanmin(x), left)
right = max(np.nanmax(x), right)
return left, right
6 changes: 3 additions & 3 deletions pandas/tests/extension/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

def make_data():
N = 100
left = np.random.uniform(size=N).cumsum()
right = left + np.random.uniform(size=N)
return [Interval(l, r) for l, r in zip(left, right)]
left_array = np.random.uniform(size=N).cumsum()
right_array = left_array + np.random.uniform(size=N)
return [Interval(left, right) for left, right in zip(left_array, right_array)]


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/methods/test_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def test_to_dict(self, mapping):
]
assert isinstance(recons_data, list)
assert len(recons_data) == 3
for l, r in zip(recons_data, expected_records):
tm.assert_dict_equal(l, r)
for left, right in zip(recons_data, expected_records):
tm.assert_dict_equal(left, right)

# GH#10844
recons_data = DataFrame(test_data).to_dict("index")
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/interval/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def get_kwargs_from_breaks(self, breaks, closed="right"):
return {"data": breaks}

ivs = [
Interval(l, r, closed) if notna(l) else l
for l, r in zip(breaks[:-1], breaks[1:])
Interval(left, right, closed) if notna(left) else left
for left, right in zip(breaks[:-1], breaks[1:])
]

if isinstance(breaks, list):
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def test_properties(self, closed):

assert index.closed == closed

ivs = [Interval(l, r, closed) for l, r in zip(range(10), range(1, 11))]
ivs = [
Interval(left, right, closed)
for left, right in zip(range(10), range(1, 11))
]
expected = np.array(ivs, dtype=object)
tm.assert_numpy_array_equal(np.asarray(index), expected)

Expand All @@ -74,8 +77,8 @@ def test_properties(self, closed):
assert index.closed == closed

ivs = [
Interval(l, r, closed) if notna(l) else np.nan
for l, r in zip(expected_left, expected_right)
Interval(left, right, closed) if notna(left) else np.nan
for left, right in zip(expected_left, expected_right)
]
expected = np.array(ivs, dtype=object)
tm.assert_numpy_array_equal(np.asarray(index), 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 @@ -817,8 +817,8 @@ def test_pyint_engine():
# integers, rather than uint64.
N = 5
keys = [
tuple(l)
for l in [
tuple(arr)
for arr in [
[0] * 10 * N,
[1] * 10 * N,
[2] * 10 * N,
Expand Down
Loading