diff --git a/pandas/core/aggregation.py b/pandas/core/aggregation.py index a8a761b5f4aac..7a1a5f5b30590 100644 --- a/pandas/core/aggregation.py +++ b/pandas/core/aggregation.py @@ -162,7 +162,7 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i order = [] columns, pairs = list(zip(*kwargs.items())) - for name, (column, aggfunc) in zip(columns, pairs): + for column, aggfunc in pairs: aggspec[column].append(aggfunc) order.append((column, com.get_callable_name(aggfunc) or aggfunc)) diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 51f7b44f6d69d..2b95eedf74b5c 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -789,7 +789,7 @@ def is_in_obj(gpr) -> bool: # lambda here return False - for i, (gpr, level) in enumerate(zip(keys, levels)): + for gpr, level in zip(keys, levels): if is_in_obj(gpr): # df.groupby(df['name']) in_axis, name = True, gpr.name diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index ae0f853db628e..efddd67ee9c7b 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2248,7 +2248,7 @@ def _convert_key(self, key, is_setter: bool = False): """ Require integer args. (and convert to label arguments) """ - for a, i in zip(self.obj.axes, key): + for i in key: if not is_integer(i): raise ValueError("iAt based indexing can only have integer indexers") return key diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index df5cd66060659..be5224fe32ae1 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -26,7 +26,7 @@ def _iter_block_pairs( # At this point we have already checked the parent DataFrames for # assert rframe._indexed_same(lframe) - for n, blk in enumerate(left.blocks): + for blk in left.blocks: locs = blk.mgr_locs blk_vals = blk.values @@ -40,7 +40,7 @@ def _iter_block_pairs( # assert len(rblks) == 1, rblks # assert rblks[0].shape[0] == 1, rblks[0].shape - for k, rblk in enumerate(rblks): + for rblk in rblks: right_ea = rblk.values.ndim == 1 lvals, rvals = _get_same_shape_values(blk, rblk, left_ea, right_ea) diff --git a/pandas/io/excel/_odfreader.py b/pandas/io/excel/_odfreader.py index 0278b22995089..2b1ebf0097778 100644 --- a/pandas/io/excel/_odfreader.py +++ b/pandas/io/excel/_odfreader.py @@ -101,12 +101,12 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: table: List[List[Scalar]] = [] - for i, sheet_row in enumerate(sheet_rows): + for sheet_row in sheet_rows: sheet_cells = [x for x in sheet_row.childNodes if x.qname in cell_names] empty_cells = 0 table_row: List[Scalar] = [] - for j, sheet_cell in enumerate(sheet_cells): + for sheet_cell in sheet_cells: if sheet_cell.qname == table_cell_name: value = self._get_cell_value(sheet_cell, convert_float) else: diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index 5c7255d5e6ee4..c9dc87ec0588b 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -307,7 +307,7 @@ def build_tree(self) -> bytes: f"{self.prefix_uri}{self.root_name}", attrib=self.other_namespaces() ) - for k, d in self.frame_dicts.items(): + for d in self.frame_dicts.values(): self.d = d self.elem_row = SubElement(self.root, f"{self.prefix_uri}{self.row_name}") @@ -477,7 +477,7 @@ def build_tree(self) -> bytes: self.root = Element(f"{self.prefix_uri}{self.root_name}", nsmap=self.namespaces) - for k, d in self.frame_dicts.items(): + for d in self.frame_dicts.values(): self.d = d self.elem_row = SubElement(self.root, f"{self.prefix_uri}{self.row_name}") diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 8658bb654b787..5ee9a268bdc8c 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3540,7 +3540,7 @@ def validate_min_itemsize(self, min_itemsize): return q = self.queryables() - for k, v in min_itemsize.items(): + for k in min_itemsize: # ok, apply generally if k == "values": diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 1ec4efe7b4795..6a81e3ae43b5d 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -84,7 +84,7 @@ def _validate_color_args(self): if isinstance(self.color, dict): valid_keys = ["boxes", "whiskers", "medians", "caps"] - for key, values in self.color.items(): + for key in self.color: if key not in valid_keys: raise ValueError( f"color dict contains invalid key '{key}'. " diff --git a/pandas/tests/frame/constructors/test_from_records.py b/pandas/tests/frame/constructors/test_from_records.py index 5093b88413110..e8d0a789e7cbd 100644 --- a/pandas/tests/frame/constructors/test_from_records.py +++ b/pandas/tests/frame/constructors/test_from_records.py @@ -149,7 +149,7 @@ def test_from_records_dictlike(self): # from the dict blocks = df._to_dict_of_blocks() columns = [] - for dtype, b in blocks.items(): + for b in blocks.values(): columns.extend(b.columns) asdict = {x: y for x, y in df.items()} diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index ca222180322bf..c81bed9d93cc4 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -20,7 +20,7 @@ def test_copy_blocks(self, float_frame): # use the default copy=True, change a column blocks = df._to_dict_of_blocks(copy=True) - for dtype, _df in blocks.items(): + for _df in blocks.values(): if column in _df: _df.loc[:, column] = _df[column] + 1 @@ -34,7 +34,7 @@ def test_no_copy_blocks(self, float_frame): # use the copy=False, change a column blocks = df._to_dict_of_blocks(copy=False) - for dtype, _df in blocks.items(): + for _df in blocks.values(): if column in _df: _df.loc[:, column] = _df[column] + 1 diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 6e71b56e8182b..6d269a27e2656 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -417,7 +417,7 @@ def test_finder_daily(self): xpl1 = xpl2 = [Period("1999-1-1", freq="B").ordinal] * len(day_lst) rs1 = [] rs2 = [] - for i, n in enumerate(day_lst): + for n in day_lst: rng = bdate_range("1999-1-1", periods=n) ser = Series(np.random.randn(len(rng)), rng) _, ax = self.plt.subplots() @@ -439,7 +439,7 @@ def test_finder_quarterly(self): xpl1 = xpl2 = [Period("1988Q1").ordinal] * len(yrs) rs1 = [] rs2 = [] - for i, n in enumerate(yrs): + for n in yrs: rng = period_range("1987Q2", periods=int(n * 4), freq="Q") ser = Series(np.random.randn(len(rng)), rng) _, ax = self.plt.subplots() @@ -461,7 +461,7 @@ def test_finder_monthly(self): xpl1 = xpl2 = [Period("Jan 1988").ordinal] * len(yrs) rs1 = [] rs2 = [] - for i, n in enumerate(yrs): + for n in yrs: rng = period_range("1987Q2", periods=int(n * 12), freq="M") ser = Series(np.random.randn(len(rng)), rng) _, ax = self.plt.subplots() @@ -491,7 +491,7 @@ def test_finder_annual(self): xp = [1987, 1988, 1990, 1990, 1995, 2020, 2070, 2170] xp = [Period(x, freq="A").ordinal for x in xp] rs = [] - for i, nyears in enumerate([5, 10, 19, 49, 99, 199, 599, 1001]): + for nyears in [5, 10, 19, 49, 99, 199, 599, 1001]: rng = period_range("1987", periods=nyears, freq="A") ser = Series(np.random.randn(len(rng)), rng) _, ax = self.plt.subplots() diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index 7dcd4dc979eb2..3cc81ef851306 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -646,7 +646,7 @@ def _ex(p): return p.start_time + Timedelta(days=1, nanoseconds=-1) return Timestamp((p + p.freq).start_time.value - 1) - for i, fcode in enumerate(from_lst): + for fcode in from_lst: p = Period("1982", freq=fcode) result = p.to_timestamp().to_period(fcode) assert result == p diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index c6b998e3dbddf..98de5b2b1eb84 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -223,7 +223,7 @@ def pandas_validate(func_name: str): ) if doc.see_also: - for rel_name, rel_desc in doc.see_also.items(): + for rel_name in doc.see_also: if rel_name.startswith("pandas."): result["errors"].append( pandas_error(