From 1f7f0556a361d3f990d9d752bd12c9f49103cefd Mon Sep 17 00:00:00 2001 From: "Dr. Kashif Rasul" Date: Thu, 19 Dec 2019 21:25:12 +0100 Subject: [PATCH] fixed some types --- pts/evaluation/evaluator.py | 2 +- pts/modules/distribution_output.py | 2 +- pts/transform/sampler.py | 5 +++-- pts/transform/split.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pts/evaluation/evaluator.py b/pts/evaluation/evaluator.py index 723bf04..cde3925 100644 --- a/pts/evaluation/evaluator.py +++ b/pts/evaluation/evaluator.py @@ -113,7 +113,7 @@ class Evaluator: @staticmethod def extract_pred_target( time_series: Union[pd.Series, pd.DataFrame], - forecast: Forecast) -> Union[pd.Series, pd.DataFrame]: + forecast: Forecast) -> np.ndarray: """ Parameters diff --git a/pts/modules/distribution_output.py b/pts/modules/distribution_output.py index c839bc4..091bd9f 100644 --- a/pts/modules/distribution_output.py +++ b/pts/modules/distribution_output.py @@ -68,7 +68,7 @@ class Output(ABC): pass -class DistributionOutput(Output): +class DistributionOutput(Output, ABC): distr_cls: type def distribution( diff --git a/pts/transform/sampler.py b/pts/transform/sampler.py index 8fa7bd3..56924e1 100644 --- a/pts/transform/sampler.py +++ b/pts/transform/sampler.py @@ -18,7 +18,7 @@ import numpy as np from pts.dataset.stat import ScaleHistogram -class InstanceSampler: +class InstanceSampler(ABC): """ An InstanceSampler is called with the time series and the valid index bounds a, b and should return a set of indices a <= i <= b @@ -41,8 +41,9 @@ class InstanceSampler: Selected points to sample """ + @abstractmethod def __call__(self, ts: np.ndarray, a: int, b: int) -> np.ndarray: - raise NotImplementedError() + pass class UniformSplitSampler(InstanceSampler): diff --git a/pts/transform/split.py b/pts/transform/split.py index 431a629..fbea518 100644 --- a/pts/transform/split.py +++ b/pts/transform/split.py @@ -12,7 +12,7 @@ # permissions and limitations under the License. from functools import lru_cache -from typing import Iterator, List, Optional +from typing import Iterator, List, Optional, Union import numpy as np import pandas as pd @@ -152,7 +152,7 @@ class InstanceSplitter(FlatMapTransformation): # the prediction length during training, so we just skip these. # If we want to include them we would need to pad and to mask # the loss. - sampling_indices: List[int] = [] + sampling_indices: Union[np.ndarray, List[int]] = [] else: if self.pick_incomplete: sampling_indices = self.train_sampler(