diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b58ce4bf..82a66929 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,15 @@ repos: - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.277' + rev: 'v0.0.278' hooks: - id: ruff args: [--fix] - repo: https://github.com/asottile/blacken-docs - rev: 1.14.0 + rev: 1.15.0 hooks: - id: blacken-docs - repo: local 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/histogram_section.py b/popmon/visualization/histogram_section.py index a50b95c9..061befe7 100644 --- a/popmon/visualization/histogram_section.py +++ b/popmon/visualization/histogram_section.py @@ -119,7 +119,7 @@ def transform(self, data_obj: dict, sections: list | None = None): ) continue - # base64 heatmap plot for each metric + # heatmap plot for each metric dates = [short_date(date) for date in df.index[:]] hists = [ df[hist_names].iloc[-i].values @@ -233,14 +233,14 @@ def _plot_histograms(feature, date, hc_list, hist_names, top_n, max_nbins: int = hist_names = [hn for i, hn in enumerate(hist_names) if i not in none_hists] # more basic checks if len(hc_list) == 0: - return {"name": date, "description": "", "plot": ""} + return {} assert_similar_hists(hc_list) # make plot. note: slow! if hc_list[0].n_dim == 1: if all(h.entries == 0 for h in hc_list): # triviality checks, skip all histograms empty - return {"name": date, "description": "", "plot": ""} + return {} props = get_hist_props(hc_list[0]) is_num = props["is_num"] @@ -259,7 +259,7 @@ def _plot_histograms(feature, date, hc_list, hist_names, top_n, max_nbins: int = # skip histograms with too many bins to plot (default more than 1000) if len(bins) > max_nbins: - return {"name": date, "description": "", "plot": ""} + return {} # normalize histograms for plotting (comparison!) in case there is more than one. if len(hc_list) >= 2: 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