Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Nov 24, 2021
1 parent aa663b0 commit c9d861f
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 116 deletions.
5 changes: 3 additions & 2 deletions popmon/alerting/alerts_summary.py
Expand Up @@ -32,8 +32,9 @@ class AlertsSummary(Module):
It combines the alerts-summaries of all individual features into an artificial feature "_AGGREGATE_".
"""
_input_keys = ("read_key", )
_output_keys = ("store_key", )

_input_keys = ("read_key",)
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
9 changes: 4 additions & 5 deletions popmon/alerting/compute_tl_bounds.py
Expand Up @@ -21,7 +21,7 @@
import copy
import fnmatch
from collections import defaultdict
from typing import Tuple, Any
from typing import Any, Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -116,7 +116,8 @@ class ComputeTLBounds(Module):
meant to be generic. Then bounds can be stored as either raw
values or as directly calculated values on the statistics of the data.
"""
_input_keys = ("read_key", )

_input_keys = ("read_key",)
_output_keys = ("store_key", "apply_funcs_key")

def __init__(
Expand Down Expand Up @@ -213,9 +214,7 @@ def transform(self, test_data: dict) -> Tuple[Any, Any]:
# --- 1. tl bounds explicitly defined for a particular feature
if feature in pkeys:
explicit_cols = [
pcol
for pcol in pkeys[feature]
if pcol in test_df.columns
pcol for pcol in pkeys[feature] if pcol in test_df.columns
]
implicit_cols = set(pkeys[feature]) - set(explicit_cols)

Expand Down
12 changes: 9 additions & 3 deletions popmon/analysis/apply_func.py
Expand Up @@ -33,8 +33,9 @@ class ApplyFunc(Module):
Extra parameters (kwargs) can be passed to the apply function.
"""

_input_keys = ("apply_to_key", "assign_to_key", "apply_funcs_key")
_output_keys = ("store_key", )
_output_keys = ("store_key",)

def __init__(
self,
Expand Down Expand Up @@ -85,7 +86,7 @@ def __init__(

def get_description(self):
if len(self.apply_funcs) > 0:
return " and ".join([x['func'].__name__ for x in self.apply_funcs])
return " and ".join([x["func"].__name__ for x in self.apply_funcs])
elif self.apply_funcs_key:
return f"functions from arg '{self.apply_funcs_key}'"
else:
Expand Down Expand Up @@ -139,7 +140,12 @@ def add_apply_func(
}
)

def transform(self, apply_to_data: dict, assign_to_data: Optional[dict] = None, apply_funcs: Optional[list] = None):
def transform(
self,
apply_to_data: dict,
assign_to_data: Optional[dict] = None,
apply_funcs: Optional[list] = None,
):
"""
Apply functions to specified feature and metrics
Expand Down
11 changes: 2 additions & 9 deletions popmon/analysis/comparison/hist_comparer.py
Expand Up @@ -380,16 +380,9 @@ def __init__(
assign_to_key = read_key

# make reference histogram(s)
hist_collector = ApplyFunc(
apply_to_key=read_key,
assign_to_key=assign_to_key
)
hist_collector = ApplyFunc(apply_to_key=read_key, assign_to_key=assign_to_key)
hist_collector.add_apply_func(
func=func_hist_collector,
hist_name=hist_col,
suffix="",
*args,
**kwargs
func=func_hist_collector, hist_name=hist_col, suffix="", *args, **kwargs
)

# do histogram comparison
Expand Down
5 changes: 3 additions & 2 deletions popmon/analysis/merge_statistics.py
Expand Up @@ -27,8 +27,9 @@

class MergeStatistics(Module):
"""Merging dictionaries of features containing dataframes with statistics as its values."""
_input_keys = ("read_keys", )
_output_keys = ("store_key", )

_input_keys = ("read_keys",)
_output_keys = ("store_key",)

def __init__(self, read_keys: List[str], store_key: str):
"""Initialize an instance of MergeStatistics.
Expand Down
5 changes: 3 additions & 2 deletions popmon/analysis/profiling/hist_profiler.py
Expand Up @@ -57,8 +57,9 @@ class HistProfiler(Module):
:param str index_col: key for index in split dictionary
:param dict stats_functions: function_name, function(bin_labels, bin_counts) dictionary
"""
_input_keys = ("read_key", )
_output_keys = ("store_key", )

_input_keys = ("read_key",)
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
11 changes: 2 additions & 9 deletions popmon/analysis/profiling/pull_calculator.py
Expand Up @@ -131,11 +131,7 @@ def __init__(
:param args: (tuple, optional): residual args passed on to mean and std functions
:param kwargs: (dict, optional): residual kwargs passed on to mean and std functions
"""
kws = {
"window": window,
"shift": shift,
**kwargs
}
kws = {"window": window, "shift": shift, **kwargs}
super().__init__(
rolling_mean,
rolling_std,
Expand Down Expand Up @@ -186,10 +182,7 @@ def __init__(
:param args: (tuple, optional): residual args passed on to mean and std functions
:param kwargs: (dict, optional): residual kwargs passed on to mean and std functions
"""
kws = {
"shift": shift,
**kwargs
}
kws = {"shift": shift, **kwargs}
super().__init__(
expanding_mean,
expanding_std,
Expand Down
21 changes: 10 additions & 11 deletions popmon/base/module.py
Expand Up @@ -24,6 +24,7 @@

class Module(ABC):
"""Base class used for modules in a pipeline."""

_input_keys = None
_output_keys = None

Expand Down Expand Up @@ -101,18 +102,12 @@ def get_features(self, all_features: list) -> list:
features = [k for k in features if k not in self.ignore_features]

features_not_in_input = [
feature
for feature in features
if feature not in all_features
feature for feature in features if feature not in all_features
]
for feature in features_not_in_input:
self.logger.warning(f'Feature "{feature}" not in input data; skipping.')

features = [
feature
for feature in features
if feature in all_features
]
features = [feature for feature in features if feature in all_features]
return features

def _transform(self, datastore):
Expand All @@ -130,7 +125,9 @@ def _transform(self, datastore):
else:
inputs[key] = None

self.logger.debug(f"load(key={key}, key_value={key_value}, value={str(inputs[key]):.100s})")
self.logger.debug(
f"load(key={key}, key_value={key_value}, value={str(inputs[key]):.100s})"
)

# cache datastore
self._datastore = datastore
Expand All @@ -145,8 +142,10 @@ def _transform(self, datastore):

for k, v in zip(self._output_keys, outputs):
key_value = self.__dict__[k]
self.logger.debug(f"store(key={k}, key_value={key_value}, value={str(v):.100s})")
if key_value and len(key_value) > 0: # and v is not None:
self.logger.debug(
f"store(key={k}, key_value={key_value}, value={str(v):.100s})"
)
if key_value and len(key_value) > 0: # and v is not None:
datastore[key_value] = v

return datastore
Expand Down
22 changes: 8 additions & 14 deletions popmon/base/pipeline.py
Expand Up @@ -85,9 +85,7 @@ def visualize(self, versioned=True, funcs=None, dsets=None):
for module in self.modules:
name = module.__class__.__name__
if isinstance(module, Pipeline):
modules.append(
module.visualize(versioned, funcs, dsets)
)
modules.append(module.visualize(versioned, funcs, dsets))
else:
in_keys = module.get_inputs()

Expand Down Expand Up @@ -122,19 +120,15 @@ def visualize(self, versioned=True, funcs=None, dsets=None):

modules.append(
{
'type': 'module',
'name': f'{name}',
'i': f'{funcs[name][id(module)]}',
'desc': module.get_description(),
'in': in_keys,
'out': out_keys
"type": "module",
"name": f"{name}",
"i": f"{funcs[name][id(module)]}",
"desc": module.get_description(),
"in": in_keys,
"out": out_keys,
}
)
data = {
'type': 'subgraph',
'name': self.__class__.__name__,
'modules': modules
}
data = {"type": "subgraph", "name": self.__class__.__name__, "modules": modules}
return data

def to_json(self, file_name, versioned=True):
Expand Down
7 changes: 3 additions & 4 deletions popmon/hist/hist_splitter.py
Expand Up @@ -37,8 +37,8 @@ class HistSplitter(Module):
where time is the index and each row is a x:y histogram.
"""

_input_keys = ("read_key", )
_output_keys = ("store_key", )
_input_keys = ("read_key",)
_output_keys = ("store_key",)

def __init__(
self,
Expand Down Expand Up @@ -153,7 +153,6 @@ def transform(self, data: dict) -> dict:

# turn divided dicts into dataframes with index
divided = {
k: pd.DataFrame(v).set_index(self.index_col)
for k, v in divided.items()
k: pd.DataFrame(v).set_index(self.index_col) for k, v in divided.items()
}
return divided
4 changes: 2 additions & 2 deletions popmon/io/file_reader.py
Expand Up @@ -28,8 +28,8 @@
class FileReader(Module):
"""Module to read contents from a file, transform the contents with a function and write them to the datastore."""

_input_keys = tuple()
_output_keys = ("store_key", )
_input_keys = ()
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions popmon/io/file_writer.py
Expand Up @@ -28,8 +28,9 @@

class FileWriter(Module):
"""Module transforms specific datastore content and writes it to a file."""
_input_keys = ("read_key", )
_output_keys = ("store_key", )

_input_keys = ("read_key",)
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
8 changes: 1 addition & 7 deletions popmon/pipeline/metrics_pipelines.py
Expand Up @@ -382,13 +382,7 @@ def metrics_rolling_reference(
),
ApplyFunc(
apply_to_key="traffic_lights",
apply_funcs=[
{
"func": traffic_light_summary,
"axis": 1,
"suffix": ""
}
],
apply_funcs=[{"func": traffic_light_summary, "axis": 1, "suffix": ""}],
assign_to_key="alerts",
msg="Generating traffic light alerts summary.",
),
Expand Down
5 changes: 3 additions & 2 deletions popmon/pipeline/report.py
Expand Up @@ -425,8 +425,9 @@ class StabilityReport(Module):
after running the pipeline and generating the report. Report can be represented
as a HTML string, HTML file or Jupyter notebook's cell output.
"""
_input_keys = ("read_key", )
_output_keys = tuple()

_input_keys = ("read_key",)
_output_keys = ()

def __init__(self, read_key="html_report"):
"""Initialize an instance of StabilityReport.
Expand Down
2 changes: 1 addition & 1 deletion popmon/stitching/hist_stitcher.py
Expand Up @@ -29,7 +29,7 @@ class HistStitcher(Module):
"""Module stitches histograms by date"""

_input_keys = ("read_key", "delta_key")
_output_keys = ("store_key", )
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions popmon/visualization/alert_section_generator.py
Expand Up @@ -36,8 +36,9 @@ class AlertSectionGenerator(Module):
combines all the plots into a list which is stored together with the section name in a dictionary
which later will be used for the report generation.
"""

_input_keys = ("read_key", "static_bounds", "dynamic_bounds", "store_key")
_output_keys = ("store_key", )
_output_keys = ("store_key",)

def __init__(
self,
Expand Down Expand Up @@ -106,7 +107,7 @@ def transform(
data_obj: dict,
static_bounds: Optional[dict] = None,
dynamic_bounds: Optional[dict] = None,
sections: Optional[list] = None
sections: Optional[list] = None,
):
assert isinstance(data_obj, dict)
if static_bounds is None:
Expand Down
3 changes: 2 additions & 1 deletion popmon/visualization/histogram_section.py
Expand Up @@ -37,8 +37,9 @@

class HistogramSection(Module):
"""This module plots histograms of all selected features for the last 'n' periods."""

_input_keys = ("read_key", "store_key")
_output_keys = ("store_key", )
_output_keys = ("store_key",)

def __init__(
self,
Expand Down
5 changes: 3 additions & 2 deletions popmon/visualization/report_generator.py
Expand Up @@ -29,8 +29,9 @@ class ReportGenerator(Module):
"""This module takes already prepared section data, renders HTML section template with the data and
glues sections together into one compressed report which is created based on the provided template.
"""
_input_keys = ("read_key", )
_output_keys = ("store_key", )

_input_keys = ("read_key",)
_output_keys = ("store_key",)

def __init__(self, read_key, store_key):
"""Initialize an instance of ReportGenerator.
Expand Down
11 changes: 9 additions & 2 deletions popmon/visualization/section_generator.py
Expand Up @@ -35,8 +35,9 @@ class SectionGenerator(Module):
combines all the plots into a list which is stored together with the section name in a dictionary
which later will be used for the report generation.
"""

_input_keys = ("read_key", "static_bounds", "dynamic_bounds", "store_key")
_output_keys = ("store_key", )
_output_keys = ("store_key",)

def __init__(
self,
Expand Down Expand Up @@ -98,7 +99,13 @@ def __init__(
def get_description(self):
return self.section_name

def transform(self, data_obj: dict, static_bounds: Optional[dict] = None, dynamic_bounds: Optional[dict] = None, sections: Optional[list] = None):
def transform(
self,
data_obj: dict,
static_bounds: Optional[dict] = None,
dynamic_bounds: Optional[dict] = None,
sections: Optional[list] = None,
):
if static_bounds is None:
static_bounds = {}
if dynamic_bounds is None:
Expand Down

0 comments on commit c9d861f

Please sign in to comment.