From fc3456b4f7cf58bf2cfdda2a6184ee550c3a7edd Mon Sep 17 00:00:00 2001 From: ywz Date: Tue, 26 Jul 2022 13:04:50 +0800 Subject: [PATCH] Revise Timeseries class --- omnixai/data/timeseries.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/omnixai/data/timeseries.py b/omnixai/data/timeseries.py index 475f7758..bfa2b9f6 100644 --- a/omnixai/data/timeseries.py +++ b/omnixai/data/timeseries.py @@ -82,14 +82,14 @@ def __getitem__(self, i: Union[int, slice, list]): ) @property - def ts_len(self): + def ts_len(self) -> int: """ Returns the length of the time series. """ return self.data.shape[0] @property - def shape(self): + def shape(self) -> tuple: """ Returns the raw data shape, e.g., (timestamps, num_variables). @@ -108,7 +108,7 @@ def num_samples(self) -> int: return 1 @property - def values(self): + def values(self) -> np.ndarray: """ Returns the raw values of the data object. @@ -117,7 +117,7 @@ def values(self): return self.data @property - def columns(self): + def columns(self) -> List: """ Gets the metric/variable names. @@ -126,7 +126,7 @@ def columns(self): return self.variable_names @property - def index(self): + def index(self) -> np.ndarray: """ Gets the timestamps. @@ -146,7 +146,7 @@ def to_pd(self) -> pd.DataFrame: index=self.timestamps ) - def to_numpy(self, copy=True): + def to_numpy(self, copy=True) -> np.ndarray: """ Converts `Timeseries` to `np.ndarray`. @@ -164,21 +164,6 @@ def copy(self): """ return Timeseries.from_pd(self.to_pd()) - def sort_timestamps(self, only_timestamp=False): - """ - Sorts the samples according to the timestamps. - - :param only_timestamp: If True, only timestamps are sorted. - If False, both timestamps and data are sorted. - """ - if only_timestamp: - self.timestamps = np.sort(self.timestamps) - else: - indices = np.argsort(self.timestamps) - self.timestamps = self.timestamps[indices] - self.data = self.data[indices] - return self - @classmethod def from_pd(cls, df): """