Skip to content

Commit

Permalink
Merge pull request #282 from ing-bank/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
sbrugman authored Jul 18, 2023
2 parents f2a0f93 + d10054a commit 2ae6247
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 7 additions & 25 deletions popmon/analysis/hist_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -411,37 +407,27 @@ 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
if isinstance(hist_list[0], histogrammar.Bin):
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

Expand All @@ -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

Expand Down
4 changes: 1 addition & 3 deletions popmon/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?'
)


Expand Down
8 changes: 4 additions & 4 deletions popmon/visualization/histogram_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions popmon/visualization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ae6247

Please sign in to comment.