converted dates and values to properties
ts['dates'] and ts['values'] keys implemted
This commit is contained in:
parent
439fa86b5c
commit
141ec97a2c
@ -142,13 +142,36 @@ class TimeSeriesCore:
|
|||||||
data = _preprocess_timeseries(data, date_format=date_format)
|
data = _preprocess_timeseries(data, date_format=date_format)
|
||||||
|
|
||||||
self.time_series = dict(data)
|
self.time_series = dict(data)
|
||||||
self.dates = list(self.time_series)
|
|
||||||
if len(self.time_series) != len(data):
|
if len(self.time_series) != len(data):
|
||||||
print("Warning: The input data contains duplicate dates which have been ignored.")
|
print("Warning: The input data contains duplicate dates which have been ignored.")
|
||||||
self.start_date = self.dates[0]
|
|
||||||
self.end_date = self.dates[-1]
|
|
||||||
self.frequency = getattr(AllFrequencies, frequency)
|
self.frequency = getattr(AllFrequencies, frequency)
|
||||||
self.iter_num = -1
|
self.iter_num = -1
|
||||||
|
self._dates = None
|
||||||
|
self._values = None
|
||||||
|
self._start_date = None
|
||||||
|
self._end_date = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dates(self):
|
||||||
|
if self._dates is None or len(self._dates) != len(self.time_series):
|
||||||
|
self._dates = list(self.time_series.keys())
|
||||||
|
|
||||||
|
return self._dates
|
||||||
|
|
||||||
|
@property
|
||||||
|
def values(self):
|
||||||
|
if self._values is None or len(self._values) != len(self.time_series):
|
||||||
|
self._values = list(self.time_series.values())
|
||||||
|
|
||||||
|
return self._values
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_date(self):
|
||||||
|
return self.dates[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_date(self):
|
||||||
|
return self.dates[-1]
|
||||||
|
|
||||||
def _get_printable_slice(self, n: int):
|
def _get_printable_slice(self, n: int):
|
||||||
"""Returns a slice of the dataframe from beginning and end"""
|
"""Returns a slice of the dataframe from beginning and end"""
|
||||||
@ -199,6 +222,10 @@ class TimeSeriesCore:
|
|||||||
elif isinstance(key, datetime.datetime):
|
elif isinstance(key, datetime.datetime):
|
||||||
item = (key, self.time_series[key])
|
item = (key, self.time_series[key])
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
|
if key == 'dates':
|
||||||
|
return self.dates
|
||||||
|
elif key == 'values':
|
||||||
|
return list(self.time_series.values())
|
||||||
try:
|
try:
|
||||||
dt_key = datetime.datetime.strptime(key, FincalOptions.date_format)
|
dt_key = datetime.datetime.strptime(key, FincalOptions.date_format)
|
||||||
item = (dt_key, self.time_series[dt_key])
|
item = (dt_key, self.time_series[dt_key])
|
||||||
|
Loading…
Reference in New Issue
Block a user