Skip to content

Commit

Permalink
Merge f0eefb5 into 720a746
Browse files Browse the repository at this point in the history
  • Loading branch information
tellezsanti committed Mar 4, 2020
2 parents 720a746 + f0eefb5 commit c0a1822
Show file tree
Hide file tree
Showing 23 changed files with 2,338 additions and 984 deletions.
68 changes: 68 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# mypy.ini
[mypy]
disallow_untyped_defs = True
disallow_untyped_calls = True

[mypy-pytest]
ignore_missing_imports = True

[mypy-scipy.stats]
ignore_missing_imports = True

[mypy-sklearn.decomposition]
ignore_missing_imports = True

[mypy-setuptools]
ignore_missing_imports = True

[mypy-sklearn.cluster]
ignore_missing_imports = True

[mypy-sklearn.neighbors]
ignore_missing_imports = True

[mypy-sklearn.ensemble]
ignore_missing_imports = True

[mypy-sklearn.svm]
ignore_missing_imports = True

[mypy-sklearn.linear_model]
ignore_missing_imports = True

[mypy-numpy]
ignore_missing_imports = True

[mypy-pandas]
ignore_missing_imports = True

[mypy-sphinx_rtd_theme]
ignore_missing_imports = True

[mypy-matplotlib]
ignore_missing_imports = True

[mypy-matplotlib.pyplot]
ignore_missing_imports = True

[mypy-matplotlib.collections]
ignore_missing_imports = True

[mypy-matplotlib.lines]
ignore_missing_imports = True

[mypy-matplotlib.patches]
ignore_missing_imports = True

[mypy-statsmodels.tsa.seasonal]
ignore_missing_imports = True

[mypy-statsmodels.tsa.stattools]
ignore_missing_imports = True

[mypy-pandas.plotting]
ignore_missing_imports = True

[mypy-statsmodels]
ignore_missing_imports = True

69 changes: 48 additions & 21 deletions src/adtk/_aggregator_base.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from typing import Union, List, Dict, Tuple
import pandas as pd
from ._base import _NonTrainableModel

from ._base import _Model


class _Aggregator(_Model):
_need_fit = False

def _fit(self, lists):
pass

def _predict(self, lists):
class _Aggregator(_NonTrainableModel):
def _predict(
self,
lists: Union[
pd.DataFrame,
Dict[str, Union[pd.Series, pd.DataFrame]],
Dict[
str,
List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
],
],
) -> Union[
pd.Series, List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]]
]:
if isinstance(lists, dict):
if not (
all([isinstance(lst, list) for lst in lists.values()])
Expand All @@ -33,7 +40,19 @@ def _predict(self, lists):
)
return self._predict_core(lists)

def aggregate(self, lists):
def aggregate(
self,
lists: Union[
pd.DataFrame,
Dict[str, Union[pd.Series, pd.DataFrame]],
Dict[
str,
List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
],
],
) -> Union[
pd.Series, List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]]
]:
"""Aggregate multiple lists of anomalies into one.
Parameters
Expand All @@ -46,28 +65,36 @@ def aggregate(self, lists):
- If a dict of Series/DataFrame, every value of the dict is a
binary Series/DataFrame representing a list / a set of lists of
anomalies;
- If a dict of list, every value of the dict is a list of pandas
Timestamps representing anomalous time points.
- If a dict of list, every value of the dict is a list of events
where each event is represented as a pandas Timestamp if it is
a singular time point or a 2-tuple of pandas Timestamps if it is
a time interval.
Returns
-------
list of pandas TimeStamps, or a binary pandas Series
list or a binary pandas Series
Aggregated list of anomalies.
- If input is a pandas DataFrame or a dict of Series/DataFrame,
return a binary Series;
- If input is a dict of list, return a list.
- If input is a dict of list, return a list of events.
"""
return self._predict(lists)

def predict(self, lists, *args, **kwargs):
"""
Alias of `aggregate`.
"""
return self.aggregate(lists)

def fit_predict(self, lists, *args, **kwargs):
def predict(
self,
lists: Union[
pd.DataFrame,
Dict[str, Union[pd.Series, pd.DataFrame]],
Dict[
str,
List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
],
],
) -> Union[
pd.Series, List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]]
]:
"""
Alias of `aggregate`.
"""
Expand Down

0 comments on commit c0a1822

Please sign in to comment.