From eb4910ad05e212714aff2472a0483fe3be92effd Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Sun, 9 Jul 2023 10:38:58 +0000 Subject: [PATCH 1/4] ci: dependency update --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b58ce4bf..8c2d4bfa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - 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 From 872c6fb1fb5f0323ca92a76a1f954d7fa95ec668 Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Tue, 11 Jul 2023 17:51:54 +0000 Subject: [PATCH 2/4] ci: dependency update --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8c2d4bfa..e4b77866 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ 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 From 93553b20cb93cf1b3661569b18d8abf728617e9e Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Tue, 18 Jul 2023 11:53:06 +0200 Subject: [PATCH 3/4] fix: breaking plot when feature contains extreme values Closes https://github.com/ing-bank/popmon/issues/281 --- popmon/visualization/histogram_section.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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: From d10054a007f7544425f9daade174b5e45c8bd88f Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Tue, 18 Jul 2023 11:53:20 +0200 Subject: [PATCH 4/4] 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