From d10054a007f7544425f9daade174b5e45c8bd88f Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Tue, 18 Jul 2023 11:53:20 +0200 Subject: [PATCH] style: linting --- .pre-commit-config.yaml | 2 +- popmon/analysis/hist_numpy.py | 32 +++++++------------------------- popmon/resources.py | 4 +--- popmon/visualization/utils.py | 4 +--- pyproject.toml | 3 ++- 5 files changed, 12 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4b77866..82a66929 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.277' + rev: 'v0.0.278' hooks: - id: ruff args: [--fix] diff --git a/popmon/analysis/hist_numpy.py b/popmon/analysis/hist_numpy.py index edcfc6d4..1fec1428 100644 --- a/popmon/analysis/hist_numpy.py +++ b/popmon/analysis/hist_numpy.py @@ -382,11 +382,7 @@ def check_similar_hists( return True for hist in hist_list: if not isinstance(hist, assert_type): - raise TypeError( - "Input histogram type {htype} not of {htypes}.".format( - htype=type(hist), htypes=assert_type - ) - ) + raise TypeError(f"Input histogram type {type(hist)} not of {assert_type}.") # perform similarity checks on: # - number of dimensions # - histogram type @@ -411,11 +407,7 @@ def check_similar_hists( # Make this consistent first. types = [get_contentType(hist) for hist in hist_list] if types.count(types[0]) != len(types): - warnings.warn( - "Input histograms have inconsistent class types: {types}".format( - types=types - ) - ) + warnings.warn(f"Input histograms have inconsistent class types: {types}") return False # Check Bin attributes @@ -423,25 +415,19 @@ def check_similar_hists( nums = [hist.num for hist in hist_list] if nums.count(nums[0]) != len(nums): warnings.warn( - "Input Bin histograms have inconsistent num attributes: {types}".format( - types=nums - ) + f"Input Bin histograms have inconsistent num attributes: {nums}" ) return False lows = [hist.low for hist in hist_list] if lows.count(lows[0]) != len(lows): warnings.warn( - "Input Bin histograms have inconsistent low attributes: {types}".format( - types=lows - ) + f"Input Bin histograms have inconsistent low attributes: {lows}" ) return False highs = [hist.high for hist in hist_list] if highs.count(highs[0]) != len(highs): warnings.warn( - "Input histograms have inconsistent high attributes: {types}".format( - types=highs - ) + f"Input histograms have inconsistent high attributes: {highs}" ) return False @@ -450,17 +436,13 @@ def check_similar_hists( origins = [hist.origin for hist in hist_list] if origins.count(origins[0]) != len(origins): warnings.warn( - "Input SparselyBin histograms have inconsistent origin attributes: {types}".format( - types=origins - ) + f"Input SparselyBin histograms have inconsistent origin attributes: {origins}" ) return False bws = [hist.binWidth for hist in hist_list] if bws.count(bws[0]) != len(bws): warnings.warn( - "Input SparselyBin histograms have inconsistent binWidth attributes: {types}".format( - types=bws - ) + f"Input SparselyBin histograms have inconsistent binWidth attributes: {bws}" ) return False diff --git a/popmon/resources.py b/popmon/resources.py index da82d22d..14a39857 100644 --- a/popmon/resources.py +++ b/popmon/resources.py @@ -94,9 +94,7 @@ def _resource(resource_type, name: str) -> str: return str(full_path) raise FileNotFoundError( - 'Could not find {resource_type} "{name!s}"! Does it exist?'.format( - resource_type=resource_type, name=name - ) + f'Could not find {resource_type} "{name!s}"! Does it exist?' ) diff --git a/popmon/visualization/utils.py b/popmon/visualization/utils.py index 06b05e1c..d8ae7b4e 100644 --- a/popmon/visualization/utils.py +++ b/popmon/visualization/utils.py @@ -762,9 +762,7 @@ def plot_heatmap( values = hist_values assert len(labels) == len( values - ), "labels and values have different array lengths: {:d} vs {:d}. {}".format( - len(labels), len(values), x_label - ) + ), f"labels and values have different array lengths: {len(labels):d} vs {len(values):d}. {x_label}" # plot histogram fig = px.imshow( diff --git a/pyproject.toml b/pyproject.toml index fb9db0e4..70bf35d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -164,7 +164,8 @@ ignore = [ ] "popmon/config.py" = [ - "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`, + "FA100", # Missing `from __future__ import annotations` ] # Notebooks & NBQA