diff --git a/asv_bench/benchmarks/reshape.py b/asv_bench/benchmarks/reshape.py index 21081ee23a773..9cec8a5f7d318 100644 --- a/asv_bench/benchmarks/reshape.py +++ b/asv_bench/benchmarks/reshape.py @@ -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 diff --git a/pandas/_testing.py b/pandas/_testing.py index 87e99e520ab60..da2963e167767 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -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 @@ -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 diff --git a/pandas/core/common.py b/pandas/core/common.py index d5c078b817ca0..b9e684a169154 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -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 @@ -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): @@ -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 ) diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py index a38d9cbad0d64..a9b0498081511 100644 --- a/pandas/core/dtypes/concat.py +++ b/pandas/core/dtypes/concat.py @@ -21,11 +21,11 @@ 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 ------- @@ -33,7 +33,7 @@ def _get_dtype_kinds(l) -> 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 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 27713b5bde201..6abc629c3612c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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 @@ -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 diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index ca9612258a890..11dd3598b4864 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -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] @@ -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: diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 18ebe14763797..44e165b2d06ee 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -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 diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 082c539d034eb..db34b882a3c35 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -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): diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index eb29f6c0d0c48..25e8d9acf4690 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -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: @@ -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): @@ -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 diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 890195688b1cb..21f7899f24b51 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -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 diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 3d0e30f8b9234..7122a38db9d0a 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -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) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index c01cfb9a8b487..bef2d82706ffc 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -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 diff --git a/pandas/plotting/_matplotlib/tools.py b/pandas/plotting/_matplotlib/tools.py index bec1f48f5e64a..a5b517bb8a2fc 100644 --- a/pandas/plotting/_matplotlib/tools.py +++ b/pandas/plotting/_matplotlib/tools.py @@ -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 diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index ec834118ea7a1..1bc06ee4b6397 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -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 diff --git a/pandas/tests/frame/methods/test_to_dict.py b/pandas/tests/frame/methods/test_to_dict.py index f8feef7a95eab..db96543dc69b8 100644 --- a/pandas/tests/frame/methods/test_to_dict.py +++ b/pandas/tests/frame/methods/test_to_dict.py @@ -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") diff --git a/pandas/tests/indexes/interval/test_constructors.py b/pandas/tests/indexes/interval/test_constructors.py index c0ca0b415ba8e..07e4fc937bef8 100644 --- a/pandas/tests/indexes/interval/test_constructors.py +++ b/pandas/tests/indexes/interval/test_constructors.py @@ -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): diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index fffaf3830560f..b8734ce8950f2 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -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) @@ -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) diff --git a/pandas/tests/indexes/multi/test_indexing.py b/pandas/tests/indexes/multi/test_indexing.py index e8e31aa0cef80..2b7a6ee304891 100644 --- a/pandas/tests/indexes/multi/test_indexing.py +++ b/pandas/tests/indexes/multi/test_indexing.py @@ -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, diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 9f86e78fc36c4..5eb3d9e9ec00e 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -234,8 +234,8 @@ def test_scalar_float(self, frame_or_series): tm.makePeriodIndex, ], ) - @pytest.mark.parametrize("l", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) - def test_slice_non_numeric(self, index_func, l, frame_or_series): + @pytest.mark.parametrize("idx", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) + def test_slice_non_numeric(self, index_func, idx, frame_or_series): # GH 4892 # float_indexers should raise exceptions @@ -251,7 +251,7 @@ def test_slice_non_numeric(self, index_func, l, frame_or_series): "type float" ) with pytest.raises(TypeError, match=msg): - s.iloc[l] + s.iloc[idx] msg = ( "cannot do (slice|positional) indexing " @@ -261,12 +261,12 @@ def test_slice_non_numeric(self, index_func, l, frame_or_series): ) for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: with pytest.raises(TypeError, match=msg): - idxr(s)[l] + idxr(s)[idx] # setitem msg = "slice indices must be integers or None or have an __index__ method" with pytest.raises(TypeError, match=msg): - s.iloc[l] = 0 + s.iloc[idx] = 0 msg = ( "cannot do (slice|positional) indexing " @@ -276,7 +276,7 @@ def test_slice_non_numeric(self, index_func, l, frame_or_series): ) for idxr in [lambda x: x.loc, lambda x: x]: with pytest.raises(TypeError, match=msg): - idxr(s)[l] = 0 + idxr(s)[idx] = 0 def test_slice_integer(self): @@ -294,9 +294,9 @@ def test_slice_integer(self): s = Series(range(5), index=index) # getitem - for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: + for idx in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: - result = s.loc[l] + result = s.loc[idx] # these are all label indexing # except getitem which is positional @@ -308,9 +308,9 @@ def test_slice_integer(self): self.check(result, s, indexer, False) # getitem out-of-bounds - for l in [slice(-6, 6), slice(-6.0, 6.0)]: + for idx in [slice(-6, 6), slice(-6.0, 6.0)]: - result = s.loc[l] + result = s.loc[idx] # these are all label indexing # except getitem which is positional @@ -331,13 +331,13 @@ def test_slice_integer(self): s[slice(-6.0, 6.0)] # getitem odd floats - for l, res1 in [ + for idx, res1 in [ (slice(2.5, 4), slice(3, 5)), (slice(2, 3.5), slice(2, 4)), (slice(2.5, 3.5), slice(3, 4)), ]: - result = s.loc[l] + result = s.loc[idx] if oob: res = slice(0, 0) else: @@ -352,10 +352,10 @@ def test_slice_integer(self): "type float" ) with pytest.raises(TypeError, match=msg): - s[l] + s[idx] - @pytest.mark.parametrize("l", [slice(2, 4.0), slice(2.0, 4), slice(2.0, 4.0)]) - def test_integer_positional_indexing(self, l): + @pytest.mark.parametrize("idx", [slice(2, 4.0), slice(2.0, 4), slice(2.0, 4.0)]) + def test_integer_positional_indexing(self, idx): """make sure that we are raising on positional indexing w.r.t. an integer index """ @@ -372,9 +372,9 @@ def test_integer_positional_indexing(self, l): "type float" ) with pytest.raises(TypeError, match=msg): - s[l] + s[idx] with pytest.raises(TypeError, match=msg): - s.iloc[l] + s.iloc[idx] @pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex]) def test_slice_integer_frame_getitem(self, index_func): @@ -385,9 +385,9 @@ def test_slice_integer_frame_getitem(self, index_func): s = DataFrame(np.random.randn(5, 2), index=index) # getitem - for l in [slice(0.0, 1), slice(0, 1.0), slice(0.0, 1.0)]: + for idx in [slice(0.0, 1), slice(0, 1.0), slice(0.0, 1.0)]: - result = s.loc[l] + result = s.loc[idx] indexer = slice(0, 2) self.check(result, s, indexer, False) @@ -398,12 +398,12 @@ def test_slice_integer_frame_getitem(self, index_func): "type float" ) with pytest.raises(TypeError, match=msg): - s[l] + s[idx] # getitem out-of-bounds - for l in [slice(-10, 10), slice(-10.0, 10.0)]: + for idx in [slice(-10, 10), slice(-10.0, 10.0)]: - result = s.loc[l] + result = s.loc[idx] self.check(result, s, slice(-10, 10), True) # positional indexing @@ -416,13 +416,13 @@ def test_slice_integer_frame_getitem(self, index_func): s[slice(-10.0, 10.0)] # getitem odd floats - for l, res in [ + for idx, res in [ (slice(0.5, 1), slice(1, 2)), (slice(0, 0.5), slice(0, 1)), (slice(0.5, 1.5), slice(1, 2)), ]: - result = s.loc[l] + result = s.loc[idx] self.check(result, s, res, False) # positional indexing @@ -432,11 +432,11 @@ def test_slice_integer_frame_getitem(self, index_func): "type float" ) with pytest.raises(TypeError, match=msg): - s[l] + s[idx] - @pytest.mark.parametrize("l", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) + @pytest.mark.parametrize("idx", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) @pytest.mark.parametrize("index_func", [tm.makeIntIndex, tm.makeRangeIndex]) - def test_float_slice_getitem_with_integer_index_raises(self, l, index_func): + def test_float_slice_getitem_with_integer_index_raises(self, idx, index_func): # similar to above, but on the getitem dim (of a DataFrame) index = index_func(5) @@ -445,8 +445,8 @@ def test_float_slice_getitem_with_integer_index_raises(self, l, index_func): # setitem sc = s.copy() - sc.loc[l] = 0 - result = sc.loc[l].values.ravel() + sc.loc[idx] = 0 + result = sc.loc[idx].values.ravel() assert (result == 0).all() # positional indexing @@ -456,13 +456,13 @@ def test_float_slice_getitem_with_integer_index_raises(self, l, index_func): "type float" ) with pytest.raises(TypeError, match=msg): - s[l] = 0 + s[idx] = 0 with pytest.raises(TypeError, match=msg): - s[l] + s[idx] - @pytest.mark.parametrize("l", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) - def test_slice_float(self, l, frame_or_series): + @pytest.mark.parametrize("idx", [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]) + def test_slice_float(self, idx, frame_or_series): # same as above, but for floats index = Index(np.arange(5.0)) + 0.1 @@ -472,14 +472,14 @@ def test_slice_float(self, l, frame_or_series): for idxr in [lambda x: x.loc, lambda x: x]: # getitem - result = idxr(s)[l] + result = idxr(s)[idx] assert isinstance(result, type(s)) tm.assert_equal(result, expected) # setitem s2 = s.copy() - idxr(s2)[l] = 0 - result = idxr(s2)[l].values.ravel() + idxr(s2)[idx] = 0 + result = idxr(s2)[idx].values.ravel() assert (result == 0).all() def test_floating_index_doc_example(self): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index e7831475932d9..08a15300563b8 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -814,12 +814,12 @@ def test_loc_non_unique_memory_error(self): columns = list("ABCDEFG") - def gen_test(l, l2): + def gen_test(length, l2): return pd.concat( [ DataFrame( - np.random.randn(l, len(columns)), - index=np.arange(l), + np.random.randn(length, len(columns)), + index=np.arange(length), columns=columns, ), DataFrame( diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index ce9aa16e57f1c..53d38297eafba 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -1681,7 +1681,7 @@ def test_to_string_decimal(self): def test_to_string_line_width(self): df = DataFrame(123, index=range(10, 15), columns=range(30)) s = df.to_string(line_width=80) - assert max(len(l) for l in s.split("\n")) == 80 + assert max(len(line) for line in s.split("\n")) == 80 def test_show_dimensions(self): df = DataFrame(123, index=range(10, 15), columns=range(30)) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 19eb64be1be29..e3c2f20f80ee3 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2425,8 +2425,8 @@ def test_schema(self): frame = tm.makeTimeDataFrame() create_sql = sql.get_schema(frame, "test") lines = create_sql.splitlines() - for l in lines: - tokens = l.split(" ") + for line in lines: + tokens = line.split(" ") if len(tokens) == 2 and tokens[0] == "A": assert tokens[1] == "DATETIME" @@ -2706,8 +2706,8 @@ def test_schema(self): frame = tm.makeTimeDataFrame() create_sql = sql.get_schema(frame, "test") lines = create_sql.splitlines() - for l in lines: - tokens = l.split(" ") + for line in lines: + tokens = line.split(" ") if len(tokens) == 2 and tokens[0] == "A": assert tokens[1] == "DATETIME" diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 66463a4a2358a..590758bc01fbb 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -776,8 +776,8 @@ def test_mixed_freq_hf_first(self): _, ax = self.plt.subplots() high.plot(ax=ax) low.plot(ax=ax) - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == "D" + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == "D" @pytest.mark.slow def test_mixed_freq_alignment(self): @@ -803,8 +803,8 @@ def test_mixed_freq_lf_first(self): _, ax = self.plt.subplots() low.plot(legend=True, ax=ax) high.plot(legend=True, ax=ax) - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == "D" + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == "D" leg = ax.get_legend() assert len(leg.texts) == 2 self.plt.close(ax.get_figure()) @@ -816,8 +816,8 @@ def test_mixed_freq_lf_first(self): _, ax = self.plt.subplots() low.plot(ax=ax) high.plot(ax=ax) - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == "T" + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == "T" def test_mixed_freq_irreg_period(self): ts = tm.makeTimeSeries() @@ -882,8 +882,8 @@ def test_to_weekly_resampling(self): _, ax = self.plt.subplots() high.plot(ax=ax) low.plot(ax=ax) - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq @pytest.mark.slow def test_from_weekly_resampling(self): @@ -900,9 +900,9 @@ def test_from_weekly_resampling(self): [1514, 1519, 1523, 1527, 1531, 1536, 1540, 1544, 1549, 1553, 1558, 1562], dtype=np.float64, ) - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == idxh.freq - xdata = l.get_xdata(orig=False) + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == idxh.freq + xdata = line.get_xdata(orig=False) if len(xdata) == 12: # idxl lines tm.assert_numpy_array_equal(xdata, expected_l) else: @@ -1013,8 +1013,8 @@ def test_mixed_freq_second_millisecond(self): high.plot(ax=ax) low.plot(ax=ax) assert len(ax.get_lines()) == 2 - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == "L" + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == "L" tm.close() # low to high @@ -1022,8 +1022,8 @@ def test_mixed_freq_second_millisecond(self): low.plot(ax=ax) high.plot(ax=ax) assert len(ax.get_lines()) == 2 - for l in ax.get_lines(): - assert PeriodIndex(data=l.get_xdata()).freq == "L" + for line in ax.get_lines(): + assert PeriodIndex(data=line.get_xdata()).freq == "L" @pytest.mark.slow def test_irreg_dtypes(self): @@ -1154,12 +1154,12 @@ def test_secondary_upsample(self): _, ax = self.plt.subplots() low.plot(ax=ax) ax = high.plot(secondary_y=True, ax=ax) - for l in ax.get_lines(): - assert PeriodIndex(l.get_xdata()).freq == "D" + for line in ax.get_lines(): + assert PeriodIndex(line.get_xdata()).freq == "D" assert hasattr(ax, "left_ax") assert not hasattr(ax, "right_ax") - for l in ax.left_ax.get_lines(): - assert PeriodIndex(l.get_xdata()).freq == "D" + for line in ax.left_ax.get_lines(): + assert PeriodIndex(line.get_xdata()).freq == "D" @pytest.mark.slow def test_secondary_legend(self): @@ -1259,9 +1259,9 @@ def test_format_date_axis(self): _, ax = self.plt.subplots() ax = df.plot(ax=ax) xaxis = ax.get_xaxis() - for l in xaxis.get_ticklabels(): - if len(l.get_text()) > 0: - assert l.get_rotation() == 30 + for line in xaxis.get_ticklabels(): + if len(line.get_text()) > 0: + assert line.get_rotation() == 30 @pytest.mark.slow def test_ax_plot(self): diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 9ccfdfc146eac..143bac3ad136a 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -2192,7 +2192,9 @@ def test_merge_multiindex_columns(): result = frame_x.merge(frame_y, on="id", suffixes=((l_suf, r_suf))) # Constructing the expected results - expected_labels = [l + l_suf for l in letters] + [l + r_suf for l in letters] + expected_labels = [letter + l_suf for letter in letters] + [ + letter + r_suf for letter in letters + ] expected_index = pd.MultiIndex.from_product( [expected_labels, numbers], names=["outer", "inner"] ) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index d774417e1851c..5a28cd5c418f0 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2053,8 +2053,8 @@ def test_pivot_table_empty_aggfunc(self): def test_pivot_table_no_column_raises(self): # GH 10326 - def agg(l): - return np.mean(l) + def agg(arr): + return np.mean(arr) foo = DataFrame({"X": [0, 0, 1, 1], "Y": [0, 1, 0, 1], "Z": [10, 20, 30, 40]}) with pytest.raises(KeyError, match="notpresent"): diff --git a/pandas/util/_doctools.py b/pandas/util/_doctools.py index 3a8a1a3144269..256346d482248 100644 --- a/pandas/util/_doctools.py +++ b/pandas/util/_doctools.py @@ -34,11 +34,11 @@ def _get_cells(self, left, right, vertical) -> Tuple[int, int]: """ if vertical: # calculate required number of cells - vcells = max(sum(self._shape(l)[0] for l in left), self._shape(right)[0]) - hcells = max(self._shape(l)[1] for l in left) + self._shape(right)[1] + vcells = max(sum(self._shape(df)[0] for df in left), self._shape(right)[0]) + hcells = max(self._shape(df)[1] for df in left) + self._shape(right)[1] else: - vcells = max([self._shape(l)[0] for l in left] + [self._shape(right)[0]]) - hcells = sum([self._shape(l)[1] for l in left] + [self._shape(right)[1]]) + vcells = max([self._shape(df)[0] for df in left] + [self._shape(right)[0]]) + hcells = sum([self._shape(df)[1] for df in left] + [self._shape(right)[1]]) return hcells, vcells def plot(self, left, right, labels=None, vertical: bool = True): @@ -58,7 +58,7 @@ def plot(self, left, right, labels=None, vertical: bool = True): if not isinstance(left, list): left = [left] - left = [self._conv(l) for l in left] + left = [self._conv(df) for df in left] right = self._conv(right) hcells, vcells = self._get_cells(left, right, vertical) @@ -73,8 +73,8 @@ def plot(self, left, right, labels=None, vertical: bool = True): if vertical: gs = gridspec.GridSpec(len(left), hcells) # left - max_left_cols = max(self._shape(l)[1] for l in left) - max_left_rows = max(self._shape(l)[0] for l in left) + max_left_cols = max(self._shape(df)[1] for df in left) + max_left_rows = max(self._shape(df)[0] for df in left) for i, (l, label) in enumerate(zip(left, labels)): ax = fig.add_subplot(gs[i, 0:max_left_cols]) self._make_table(ax, l, title=label, height=1.0 / max_left_rows) @@ -88,10 +88,10 @@ def plot(self, left, right, labels=None, vertical: bool = True): gs = gridspec.GridSpec(1, hcells) # left i = 0 - for l, label in zip(left, labels): - sp = self._shape(l) + for df, label in zip(left, labels): + sp = self._shape(df) ax = fig.add_subplot(gs[0, i : i + sp[1]]) - self._make_table(ax, l, title=label, height=height) + self._make_table(ax, df, title=label, height=height) i += sp[1] # right ax = plt.subplot(gs[0, i:]) diff --git a/setup.cfg b/setup.cfg index 10c7137dc2f86..7b404cb294f58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,6 @@ ignore = W504, # line break after binary operator E402, # module level import not at top of file E731, # do not assign a lambda expression, use a def - E741, # ambiguous variable name 'l' (GH#34150) C406, # Unnecessary list literal - rewrite as a dict literal. C408, # Unnecessary dict call - rewrite as a literal. C409, # Unnecessary list passed to tuple() - rewrite as a tuple literal.