Skip to content

Commit

Permalink
Merge pull request #279 from ing-bank/develop
Browse files Browse the repository at this point in the history
Release v1.4.5
  • Loading branch information
sbrugman committed Jul 6, 2023
2 parents 2a6a2d4 + f36f922 commit bf09e1d
Show file tree
Hide file tree
Showing 52 changed files with 321 additions and 300 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/license.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Expand Up @@ -4,12 +4,12 @@ repos:
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.270'
rev: 'v0.0.277'
hooks:
- id: ruff
args: [--fix]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.14.0
hooks:
- id: blacken-docs
- repo: local
Expand All @@ -24,5 +24,5 @@ repos:
hooks:
- id: nbqa-black
- id: nbqa-ruff
additional_dependencies: [ruff==v0.0.270]
additional_dependencies: [ruff==v0.0.277]

2 changes: 1 addition & 1 deletion examples/integrations/kibana/elastic_connector.py
Expand Up @@ -2,7 +2,7 @@


class ElasticConnector:
def __init__(self):
def __init__(self) -> None:
self.host = "localhost"
self.port = 9200
self.es = None
Expand Down
6 changes: 3 additions & 3 deletions popmon/alerting/alerts_summary.py
Expand Up @@ -38,11 +38,11 @@ class AlertsSummary(Module):
def __init__(
self,
read_key,
store_key="",
store_key: str = "",
features=None,
ignore_features=None,
combined_variable="_AGGREGATE_",
):
combined_variable: str = "_AGGREGATE_",
) -> None:
"""Initialize an instance of AlertsSummary module.
:param str read_key: key of input data to read from datastore.
Expand Down
58 changes: 31 additions & 27 deletions popmon/alerting/compute_tl_bounds.py
Expand Up @@ -30,7 +30,7 @@
from popmon.base import Module, Pipeline


def traffic_light_summary(row, cols=None, prefix=""):
def traffic_light_summary(row, cols=None, prefix: str = ""):
"""Make a summary of traffic light alerts present in the dataframe
Count number of green, yellow and red traffic lights.
Expand Down Expand Up @@ -60,7 +60,9 @@ def traffic_light_summary(row, cols=None, prefix=""):
return pd.Series(x)


def traffic_light(value, red_high, yellow_high, yellow_low=0, red_low=0):
def traffic_light(
value, red_high, yellow_high, yellow_low: int = 0, red_low: int = 0
) -> int:
"""Get the corresponding traffic light given a value and traffic light bounds.
:param float value: value to check
Expand Down Expand Up @@ -120,17 +122,17 @@ def __init__(
self,
read_key,
monitoring_rules=None,
store_key="",
store_key: str = "",
features=None,
ignore_features=None,
apply_funcs_key="",
apply_funcs_key: str = "",
func=None,
metrics_wide=False,
prefix="traffic_light_",
suffix="",
entire=False,
metrics_wide: bool = False,
prefix: str = "traffic_light_",
suffix: str = "",
entire: bool = False,
**kwargs,
):
) -> None:
"""Initialize an instance of TrafficLightBounds module.
:param str read_key: key of input data to read from datastore
Expand Down Expand Up @@ -171,7 +173,7 @@ def get_description(self):
"""Returns the traffic light function as description."""
return self.traffic_light_func.__name__

def _set_traffic_lights(self, feature, cols, pattern, rule):
def _set_traffic_lights(self, feature, cols, pattern, rule) -> None:
process_cols = fnmatch.filter(cols, pattern)

for pcol in process_cols:
Expand Down Expand Up @@ -250,10 +252,10 @@ def pull_bounds(
row,
red_high,
yellow_high,
yellow_low=0,
red_low=0,
suffix_mean="_mean",
suffix_std="_std",
yellow_low: int = 0,
red_low: int = 0,
suffix_mean: str = "_mean",
suffix_std: str = "_std",
cols=None,
):
"""Calculate traffic light pull bounds for list of cols
Expand Down Expand Up @@ -307,10 +309,10 @@ def df_single_op_pull_bounds(
df,
red_high,
yellow_high,
yellow_low=0,
red_low=0,
suffix_mean="_mean",
suffix_std="_std",
yellow_low: int = 0,
red_low: int = 0,
suffix_mean: str = "_mean",
suffix_std: str = "_std",
cols=None,
):
"""Calculate traffic light pull bounds for list of cols on first row only
Expand Down Expand Up @@ -341,10 +343,10 @@ def __init__(
self,
read_key,
rules,
store_key="",
suffix_mean="_mean",
suffix_std="_std",
):
store_key: str = "",
suffix_mean: str = "_mean",
suffix_std: str = "_std",
) -> None:
"""Initialize an instance of DynamicTrafficLightBounds.
:param str read_key: key of input data to read from data store, only used to extract feature list.
Expand Down Expand Up @@ -385,10 +387,10 @@ def __init__(
self,
read_key,
rules,
store_key="",
suffix_mean="_mean",
suffix_std="_std",
):
store_key: str = "",
suffix_mean: str = "_mean",
suffix_std: str = "_std",
) -> None:
"""Initialize an instance of StaticBounds.
:param str read_key: key of input data to read from data store, only used to extract feature list.
Expand Down Expand Up @@ -432,7 +434,9 @@ class TrafficLightAlerts(Pipeline):
- Apply them to profiled test statistics data
"""

def __init__(self, read_key, store_key, rules, expanded_rules_key=""):
def __init__(
self, read_key, store_key, rules, expanded_rules_key: str = ""
) -> None:
"""Initialize an instance of TrafficLightBounds.
:param str read_key: key of input data to read from data store, only used to extract feature list.
Expand Down
17 changes: 8 additions & 9 deletions popmon/analysis/apply_func.py
Expand Up @@ -16,10 +16,9 @@
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from __future__ import annotations

import warnings
from typing import Optional

import numpy as np
import pandas as pd
Expand All @@ -40,14 +39,14 @@ class ApplyFunc(Module):
def __init__(
self,
apply_to_key,
store_key="",
assign_to_key="",
apply_funcs_key="",
store_key: str = "",
assign_to_key: str = "",
apply_funcs_key: str = "",
features=None,
apply_funcs=None,
metrics=None,
msg="",
):
msg: str = "",
) -> None:
"""Initialize an instance of ApplyFunc.
:param str apply_to_key: key of the input data to apply funcs to.
Expand Down Expand Up @@ -147,8 +146,8 @@ def add_apply_func(
def transform(
self,
apply_to_data: dict,
assign_to_data: Optional[dict] = None,
apply_funcs: Optional[list] = None,
assign_to_data: dict | None = None,
apply_funcs: list | None = None,
):
"""
Apply functions to specified feature and metrics
Expand Down
2 changes: 1 addition & 1 deletion popmon/analysis/comparison/comparisons.py
Expand Up @@ -168,7 +168,7 @@ def ks(p, q, *_):
dim=1,
htype="cat",
)
def unknown_labels(hist1, hist2):
def unknown_labels(hist1, hist2) -> bool:
# check consistency of bin_labels
labels1 = hist1.keySet
labels2 = hist2.keySet
Expand Down
52 changes: 29 additions & 23 deletions popmon/analysis/comparison/hist_comparer.py
Expand Up @@ -40,7 +40,7 @@
from popmon.hist.hist_utils import COMMON_HIST_TYPES, is_numeric


def hist_compare(row, hist_name1="", hist_name2=""):
def hist_compare(row, hist_name1: str = "", hist_name2: str = ""):
"""Function to compare two histograms
Apply statistical tests to compare two input histograms, such as:
Expand Down Expand Up @@ -107,11 +107,11 @@ def __init__(
read_key,
store_key,
assign_to_key=None,
hist_col="histogram",
suffix="comp",
hist_col: str = "histogram",
suffix: str = "comp",
*args,
**kwargs,
):
) -> None:
"""Initialize an instance of RollingHistComparer.
:param func_hist_collector: histogram collection function
Expand Down Expand Up @@ -160,10 +160,10 @@ def __init__(
read_key,
store_key,
window,
shift=1,
hist_col="histogram",
suffix="roll",
):
shift: int = 1,
hist_col: str = "histogram",
suffix: str = "roll",
) -> None:
"""Initialize an instance of RollingHistComparer.
:param str read_key: key of input data to read from data store
Expand Down Expand Up @@ -201,9 +201,9 @@ def __init__(
self,
read_key,
store_key,
hist_col="histogram",
suffix="prev1",
):
hist_col: str = "histogram",
suffix: str = "prev1",
) -> None:
"""Initialize an instance of PreviousHistComparer.
:param str read_key: key of input data to read from data store
Expand All @@ -228,10 +228,10 @@ def __init__(
self,
read_key,
store_key,
shift=1,
hist_col="histogram",
suffix="expanding",
):
shift: int = 1,
hist_col: str = "histogram",
suffix: str = "expanding",
) -> None:
"""Initialize an instance of ExpandingHistComparer.
:param str read_key: key of input data to read from data store
Expand Down Expand Up @@ -267,9 +267,9 @@ def __init__(
reference_key,
assign_to_key,
store_key,
hist_col="histogram",
suffix="ref",
):
hist_col: str = "histogram",
suffix: str = "ref",
) -> None:
"""Initialize an instance of ReferenceHistComparer.
:param str reference_key: key of input data to read from data store
Expand Down Expand Up @@ -306,10 +306,10 @@ def __init__(
read_key,
store_key,
assign_to_key=None,
hist_col="histogram",
hist_col: str = "histogram",
*args,
**kwargs,
):
) -> None:
"""Initialize an instance of NormHistComparer.
:param func_hist_collector: histogram collection function
Expand Down Expand Up @@ -349,7 +349,9 @@ def __init__(
class RollingNormHistComparer(NormHistComparer):
"""Compare histogram to previous rolling normalized histograms"""

def __init__(self, read_key, store_key, window, shift=1, hist_col="histogram"):
def __init__(
self, read_key, store_key, window, shift: int = 1, hist_col: str = "histogram"
) -> None:
"""Initialize an instance of RollingNormHistComparer.
:param str read_key: key of input data to read from data store
Expand Down Expand Up @@ -383,7 +385,9 @@ def transform(self, datastore):
class ExpandingNormHistComparer(NormHistComparer):
"""Compare histogram to previous expanding normalized histograms"""

def __init__(self, read_key, store_key, shift=1, hist_col="histogram"):
def __init__(
self, read_key, store_key, shift: int = 1, hist_col: str = "histogram"
) -> None:
"""Initialize an instance of ExpandingNormHistComparer.
:param str read_key: key of input data to read from data store
Expand Down Expand Up @@ -412,7 +416,9 @@ def transform(self, datastore):
class ReferenceNormHistComparer(NormHistComparer):
"""Compare histogram to reference normalized histograms"""

def __init__(self, reference_key, assign_to_key, store_key, hist_col="histogram"):
def __init__(
self, reference_key, assign_to_key, store_key, hist_col: str = "histogram"
) -> None:
"""Initialize an instance of ReferenceNormHistComparer.
:param str reference_key: key of input data to read from data store
Expand Down

0 comments on commit bf09e1d

Please sign in to comment.