Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
fredmontet committed Feb 19, 2024
1 parent 9bab384 commit ead428b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/ontime/core/time_series/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def from_darts(ts: DartsTimeSeries) -> TimeSeries:
:return: OnTime TimeSeries
"""
return TimeSeries(ts.data_array())

@staticmethod
def from_pandas(df: pd.DataFrame, freq=None) -> TimeSeries:
"""
Expand All @@ -75,20 +75,20 @@ def from_csv(file: str, index_col=None) -> TimeSeries:
"""
df = pd.read_csv(file)
if index_col is not None:
df.index = df[index_col].astype('datetime64[ns]')
df.index = df[index_col].astype("datetime64[ns]")
del df[index_col]
return TimeSeries.from_pandas(df)

@staticmethod
def from_data(data, index=None, columns=None) -> TimeSeries:
"""
Converts data to a TimeSeries. Takes data as a dict, ndarray, Iterable or pandas DataFrame.
Assumes the index is compliant with TimeEval's canonical format.
:param data: a dict, ndarray, Iterable or pandas DataFrame
:param index: the array-like series to be used as index (will default to a range if none is specified)
:param columns: will be used for column names if there are none in the data parameter (will default to a range if nothing is specified)
:return: OnTime TimeSeries
"""
df = pd.DataFrame(data, index, columns, copy = True)
return TimeSeries.from_pandas(df)
df = pd.DataFrame(data, index, columns, copy=True)
return TimeSeries.from_pandas(df)
2 changes: 1 addition & 1 deletion src/ontime/module/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import processing
from . import data
from . import data
23 changes: 16 additions & 7 deletions src/ontime/module/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ class Dataset:

class ImportedDataset:
"""Class for dataset loaders"""
def __init__(self, dataset, args = {}):

def __init__(self, dataset, args={}):
self.dataset = dataset
self.args = args

@abstractmethod
def load(self) -> TimeSeries:
pass

class DartsDataset(ImportedDataset):
"""Darts dataset loader"""

def load(self) -> TimeSeries:
return TimeSeries.from_darts(self.dataset.load(*self.args))

class OpenMLDataset(ImportedDataset):
"""OpenML dataset loader"""

def load(self) -> TimeSeries:
self.dataset.index = self.dataset[self.args['time_col']]
self.dataset.index = self.dataset[self.args["time_col"]]
dts = dTimeSeries.from_dataframe(self.dataset, **self.args)
return TimeSeries.from_darts(dts)

Expand Down Expand Up @@ -62,6 +65,12 @@ def load(self) -> TimeSeries:
WoolyDataset = DartsDataset(dd.WoolyDataset())

# OpenML datasets
AMDStockPrices = OpenMLDataset(fetch_openml(
"AMD-Stock-Prices-Historical-Data", version=1, as_frame=True, parser="pandas").frame,
args = {'time_col': 'Date', 'fill_missing_dates':True, 'freq':'D'})
AMDStockPrices = OpenMLDataset(
fetch_openml(
"AMD-Stock-Prices-Historical-Data",
version=1,
as_frame=True,
parser="pandas",
).frame,
args={"time_col": "Date", "fill_missing_dates": True, "freq": "D"},
)

0 comments on commit ead428b

Please sign in to comment.