diff --git a/doc/source/conf.py b/doc/source/conf.py index 6671cefae9073..c73a91aa90365 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -101,20 +101,20 @@ reldir = os.path.relpath(dirname, source_path) for fname in fnames: if os.path.splitext(fname)[-1] in (".rst", ".ipynb"): - fname = os.path.relpath(os.path.join(dirname, fname), source_path) + rel_fname = os.path.relpath(os.path.join(dirname, fname), source_path) - if fname == "index.rst" and os.path.abspath(dirname) == source_path: + if rel_fname == "index.rst" and os.path.abspath(dirname) == source_path: continue if pattern == "-api" and reldir.startswith("reference"): - exclude_patterns.append(fname) + exclude_patterns.append(rel_fname) elif ( pattern == "whatsnew" and not reldir.startswith("reference") and reldir != "whatsnew" ): - exclude_patterns.append(fname) - elif single_doc and fname != pattern: - exclude_patterns.append(fname) + exclude_patterns.append(rel_fname) + elif single_doc and rel_fname != pattern: + exclude_patterns.append(rel_fname) with open(os.path.join(source_path, "index.rst.template")) as f: t = jinja2.Template(f.read()) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 0149ea545a4c5..56d505d024949 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -158,8 +158,8 @@ def _set_option(*args, **kwargs) -> None: o.validator(v) # walk the nested dict - root, k = _get_root(key) - root[k] = v + root, k_root = _get_root(key) + root[k_root] = v if o.cb: if silent: diff --git a/pandas/util/version/__init__.py b/pandas/util/version/__init__.py index 0b5e1d149daaa..ea0047f6cfd77 100644 --- a/pandas/util/version/__init__.py +++ b/pandas/util/version/__init__.py @@ -253,16 +253,16 @@ def is_devrelease(self) -> bool: def _parse_version_parts(s: str) -> Iterator[str]: for part in _legacy_version_component_re.split(s): - part = _legacy_version_replacement_map.get(part, part) + mapped_part = _legacy_version_replacement_map.get(part, part) - if not part or part == ".": + if not mapped_part or mapped_part == ".": continue - if part[:1] in "0123456789": + if mapped_part[:1] in "0123456789": # pad for numeric comparison - yield part.zfill(8) + yield mapped_part.zfill(8) else: - yield "*" + part + yield "*" + mapped_part # ensure that alpha/beta/candidate are before final yield "*final" diff --git a/pyproject.toml b/pyproject.toml index b670bc3cdd036..5f5c8895352a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -272,9 +272,7 @@ ignore = [ "B904", # Magic number "PLR2004", - # Outer loop variable overwritten by inner assignment - "PLW2901", - # Consider `elif` instead of `else` then `if` to remove indentation level + # Consider `elif` instead of `else` then `if` to remove indendation level "PLR5501", ] @@ -292,7 +290,10 @@ exclude = [ # relative imports allowed for asv_bench "asv_bench/*" = ["TID"] # to be enabled gradually -"pandas/core/*" = ["PLR5501"] +"pandas/core/*" = ["PLR5501", "PLW2901"] +"pandas/io/*" = ["PLW2901"] +"pandas/tests/*" = ["PLW2901"] +"pandas/plotting/*" = ["PLW2901"] # TCH to be enabled gradually "pandas/core/nanops.py" = ["TCH"] "pandas/_libs/*" = ["TCH"] diff --git a/scripts/no_bool_in_generic.py b/scripts/no_bool_in_generic.py index 92e2c0983b25b..1427974249702 100644 --- a/scripts/no_bool_in_generic.py +++ b/scripts/no_bool_in_generic.py @@ -50,10 +50,15 @@ def replace_bool_with_bool_t(to_replace, content: str) -> str: new_lines = [] for n, line in enumerate(content.splitlines(), start=1): + replaced_line = line if n in to_replace: for col_offset in reversed(to_replace[n]): - line = line[:col_offset] + "bool_t" + line[col_offset + 4 :] - new_lines.append(line) + replaced_line = ( + replaced_line[:col_offset] + + "bool_t" + + replaced_line[col_offset + 4 :] + ) + new_lines.append(replaced_line) return "\n".join(new_lines) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index a0eb02d069c58..487fe44e4d9bc 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -103,33 +103,33 @@ def get_api_items(api_doc_fd): previous_line = current_section = current_subsection = "" position = None for line in api_doc_fd: - line = line.strip() - if len(line) == len(previous_line): - if set(line) == set("-"): + line_stripped = line.strip() + if len(line_stripped) == len(previous_line): + if set(line_stripped) == set("-"): current_section = previous_line continue - if set(line) == set("~"): + if set(line_stripped) == set("~"): current_subsection = previous_line continue - if line.startswith(".. currentmodule::"): - current_module = line.replace(".. currentmodule::", "").strip() + if line_stripped.startswith(".. currentmodule::"): + current_module = line_stripped.replace(".. currentmodule::", "").strip() continue - if line == ".. autosummary::": + if line_stripped == ".. autosummary::": position = "autosummary" continue if position == "autosummary": - if line == "": + if line_stripped == "": position = "items" continue if position == "items": - if line == "": + if line_stripped == "": position = None continue - item = line.strip() + item = line_stripped.strip() if item in IGNORE_VALIDATION: continue func = importlib.import_module(current_module) @@ -143,7 +143,7 @@ def get_api_items(api_doc_fd): current_subsection, ) - previous_line = line + previous_line = line_stripped class PandasDocstring(Validator): diff --git a/scripts/validate_min_versions_in_sync.py b/scripts/validate_min_versions_in_sync.py index 9edce3a00a502..41296b0d2f74d 100755 --- a/scripts/validate_min_versions_in_sync.py +++ b/scripts/validate_min_versions_in_sync.py @@ -180,11 +180,11 @@ def pin_min_versions_to_yaml_file( data = data.replace(old_dep, new_dep, 1) continue toml_version = version.parse(min_dep) - yaml_versions = clean_version_list(yaml_versions, toml_version) - cleaned_yaml_versions = [x for x in yaml_versions if "-" not in x] + yaml_versions_list = clean_version_list(yaml_versions, toml_version) + cleaned_yaml_versions = [x for x in yaml_versions_list if "-" not in x] new_dep = yaml_package - for yaml_version in cleaned_yaml_versions: - new_dep += yaml_version + ", " + for clean_yaml_version in cleaned_yaml_versions: + new_dep += clean_yaml_version + ", " operator = get_operator_from(new_dep) if operator != "=": new_dep += ">=" + min_dep diff --git a/scripts/validate_rst_title_capitalization.py b/scripts/validate_rst_title_capitalization.py index 44d59aecde718..4446ed62f6b8a 100755 --- a/scripts/validate_rst_title_capitalization.py +++ b/scripts/validate_rst_title_capitalization.py @@ -229,15 +229,15 @@ def find_titles(rst_file: str) -> Iterable[tuple[str, int]]: with open(rst_file) as fd: previous_line = "" for i, line in enumerate(fd): - line = line[:-1] - line_chars = set(line) + line_no_last_elem = line[:-1] + line_chars = set(line_no_last_elem) if ( len(line_chars) == 1 and line_chars.pop() in symbols - and len(line) == len(previous_line) + and len(line_no_last_elem) == len(previous_line) ): yield re.sub(r"[`\*_]", "", previous_line), i - previous_line = line + previous_line = line_no_last_elem def main(source_paths: list[str]) -> int: diff --git a/setup.py b/setup.py index b6dfcc5fbdb0d..0c646469700da 100755 --- a/setup.py +++ b/setup.py @@ -158,8 +158,8 @@ def initialize_options(self): # clean the generated pxi files for pxifile in _pxifiles: - pxifile = pxifile.replace(".pxi.in", ".pxi") - self._clean_me.append(pxifile) + pxifile_replaced = pxifile.replace(".pxi.in", ".pxi") + self._clean_me.append(pxifile_replaced) for d in ("build", "dist"): if os.path.exists(d): diff --git a/web/pandas_web.py b/web/pandas_web.py index d1f06b6fdfa43..5e902f1b1919b 100755 --- a/web/pandas_web.py +++ b/web/pandas_web.py @@ -369,9 +369,9 @@ def get_source_files(source_path: str) -> typing.Generator[str, None, None]: Generate the list of files present in the source directory. """ for root, dirs, fnames in os.walk(source_path): - root = os.path.relpath(root, source_path) + root_rel_path = os.path.relpath(root, source_path) for fname in fnames: - yield os.path.join(root, fname) + yield os.path.join(root_rel_path, fname) def extend_base_template(content: str, base_template: str) -> str: @@ -430,8 +430,8 @@ def main( content = extend_base_template(body, context["main"]["base_template"]) context["base_url"] = "".join(["../"] * os.path.normpath(fname).count("/")) content = jinja_env.from_string(content).render(**context) - fname = os.path.splitext(fname)[0] + ".html" - with open(os.path.join(target_path, fname), "w") as f: + fname_html = os.path.splitext(fname)[0] + ".html" + with open(os.path.join(target_path, fname_html), "w") as f: f.write(content) else: shutil.copy(