diff --git a/pyproject.toml b/pyproject.toml index 91e2893..66af656 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,7 +77,6 @@ ignore = [ "BLE001", # blind-except "C401", # unnecessary-generator-set "C403", # unnecessary-list-comprehension-set - "C404", # unnecessary-list-comprehension-dict "C414", # unnecessary-double-cast-or-process "C901", # complex-structure "D100", # undocumented-public-module @@ -110,7 +109,6 @@ ignore = [ "N806", # non-lowercase-variable-in-function "PD002", # pandas-use-of-inplace-argument "PD011", # pandas-use-of-dot-values - "PERF401", # vmanual-list-comprehension "PLC0415", # import-outside-top-level "PLR0912", # too-many-branches "PLR0913", # too-many-arguments @@ -139,14 +137,10 @@ ignore = [ "PTH204", # os-path-getmtime "PTH207", # glob "PTH208", # os-listdir - "RET503", # implicit-return "RET504", # unnecessary-assign "RUF001", # ambiguous-unicode-character-string "RUF002", # ambiguous-unicode-character-docstring - "RUF012", # mutable-class-default - "RUF013", # implicit-optional "RUF015", # unnecessary-iterable-allocation-for-first-element - "RUF059", # unused-unpacked-variable "S101", # assert "S110", # try-except-pass "S301", # suspicious-pickle-usage @@ -156,8 +150,6 @@ ignore = [ "SIM102", # collapsible-if "SIM105", # suppressible-exception "SIM115", # open-file-with-context-handler - "SIM118", # in-dict-keys - "SIM212", # if-expr-with-twisted-arms "SLF001", # private-member-access "T201", # print "TD002", # missing-todo-author @@ -165,5 +157,4 @@ ignore = [ "TRY003", # raise-vanilla-args "TRY004", # type-check-without-type-error "TRY300", # try-consider-else - "UP031", # printf-string-formatting ] diff --git a/src/ivert/cli.py b/src/ivert/cli.py index 9be9e41..4c502ba 100644 --- a/src/ivert/cli.py +++ b/src/ivert/cli.py @@ -380,9 +380,7 @@ def options_list(details): from ivert.utils.configfile import Config, parse_option_descriptions config = Config() - keys = [ - k for k in config._config["DEFAULT"].keys() if k not in _OPTIONS_EXCLUDED_KEYS - ] + keys = [k for k in config._config["DEFAULT"] if k not in _OPTIONS_EXCLUDED_KEYS] if not keys: click.echo("No configurable settings found.") @@ -1502,10 +1500,11 @@ def _cache_dir(): def _fmt_size(nbytes): """Format a byte count as a human-readable string.""" - for unit in ("B", "KB", "MB", "GB", "TB"): - if nbytes < 1024 or unit == "TB": + for unit in ("B", "KB", "MB", "GB"): + if nbytes < 1024: return f"{nbytes:.1f} {unit}" nbytes /= 1024 + return f"{nbytes:.1f} TB" @ivert_cli.group("cache", invoke_without_command=True) diff --git a/src/ivert/export_vector.py b/src/ivert/export_vector.py index b984134..643f4ef 100644 --- a/src/ivert/export_vector.py +++ b/src/ivert/export_vector.py @@ -97,7 +97,10 @@ def detect_nc_kind(nc_path: str) -> str | None: # --------------------------------------------------------------------------- # Core conversion # --------------------------------------------------------------------------- -def nc_to_geodataframe(nc_path: str, classes: list = None) -> geopandas.GeoDataFrame: +def nc_to_geodataframe( + nc_path: str, + classes: list | None = None, +) -> geopandas.GeoDataFrame: """Read a single .nc granule file and return a GeoDataFrame. Parameters diff --git a/src/ivert/icesat2_database_v2.py b/src/ivert/icesat2_database_v2.py index 629df86..9ba2658 100644 --- a/src/ivert/icesat2_database_v2.py +++ b/src/ivert/icesat2_database_v2.py @@ -5,6 +5,7 @@ import os import re import shutil +from typing import ClassVar import dateparser import fetchez @@ -417,7 +418,7 @@ def _vertical_datum_to_vertical_epsg(vertical_datum: str) -> str: # to "ellipsoid" for any value it doesn't recognize (it does not raise), so # passing an EPSG code straight through would be a silent no-op rather than # an error -- always go through this lookup instead. - _EPSG_TO_GLOBATO_VERTICAL_DATUM = { + _EPSG_TO_GLOBATO_VERTICAL_DATUM: ClassVar[dict[str, str]] = { "EPSG:4979": "ellipsoid", "EPSG:3855": "geoid", } @@ -498,9 +499,7 @@ def _process_h5_to_nc( use_external_masks=use_external_masks, ) - chunks = [] - for chunk in stream: - chunks.append(pandas.DataFrame(chunk)) + chunks = [pandas.DataFrame(chunk) for chunk in stream] if not chunks: return None diff --git a/src/ivert/plot_results_slope_centrality.py b/src/ivert/plot_results_slope_centrality.py index 4f35810..b2a9a71 100644 --- a/src/ivert/plot_results_slope_centrality.py +++ b/src/ivert/plot_results_slope_centrality.py @@ -45,9 +45,7 @@ def add_lat_lons(df): def get_slopes(df, files_dirname): fnames = [os.path.join(files_dirname, fn) for fn in df.filename.unique()] slope_fnames = [fn.replace("_results.h5", "_slope.tif") for fn in fnames] - fnames_dict = dict( - [(os.path.basename(fn), sfn) for fn, sfn in zip(fnames, slope_fnames)], - ) + fnames_dict = {os.path.basename(fn): sfn for fn, sfn in zip(fnames, slope_fnames)} fn_array_dict = {} slopes = numpy.empty((len(df),), dtype=float) diff --git a/src/ivert/utils/query_yes_no.py b/src/ivert/utils/query_yes_no.py index 325d6fe..8d846af 100644 --- a/src/ivert/utils/query_yes_no.py +++ b/src/ivert/utils/query_yes_no.py @@ -19,7 +19,7 @@ def query_yes_no(question: str, default: str = "yes") -> bool: elif default.strip().lower() in ("no", "n"): prompt = " [y/N] " else: - raise ValueError("invalid default answer: '%s'" % default) + raise ValueError(f"invalid default answer: '{default}'") while True: sys.stdout.write(question + prompt) @@ -45,4 +45,4 @@ def interpret_yes_no(input_str: str) -> bool: if instr[0] in ("n", "f"): return False # Anything else is invalid - raise ValueError("invalid boolean input: '%s'" % input_str) + raise ValueError(f"invalid boolean input: '{input_str}'") diff --git a/src/ivert/validate_dem.py b/src/ivert/validate_dem.py index a883e20..1dbd31c 100644 --- a/src/ivert/validate_dem.py +++ b/src/ivert/validate_dem.py @@ -1728,7 +1728,7 @@ def _write_validation_outputs( shared_ret_values["empty_results_filename"] = empty_results_filename return files_to_export - base, ext = os.path.splitext(results_dataframe_file) + _base, ext = os.path.splitext(results_dataframe_file) ext = ext.lower().strip() if ext in (".txt", ".csv"): results_dataframe.to_csv(results_dataframe_file) @@ -2463,7 +2463,7 @@ def main( output_dir=output_dir, classes=classes_list, dem_vertical_datum=input_vdatum, - interim_data_dir=(None if not datadir else datadir), + interim_data_dir=(datadir or None), overwrite=overwrite, delete_datafiles=delete_datafiles, plot_results=plot_results,