Skip to content

Commit

Permalink
Revise Timeseries class
Browse files Browse the repository at this point in the history
  • Loading branch information
yangwenz committed Jul 26, 2022
1 parent 61ded78 commit fc3456b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions omnixai/data/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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.
Expand All @@ -117,7 +117,7 @@ def values(self):
return self.data

@property
def columns(self):
def columns(self) -> List:
"""
Gets the metric/variable names.
Expand All @@ -126,7 +126,7 @@ def columns(self):
return self.variable_names

@property
def index(self):
def index(self) -> np.ndarray:
"""
Gets the timestamps.
Expand All @@ -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`.
Expand All @@ -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):
"""
Expand Down

0 comments on commit fc3456b

Please sign in to comment.