Commit fb8057e4 authored by Arnaud Campeas's avatar Arnaud Campeas
Browse files

tsio: add from_value_date and to_value_date to get_delta

parent 32db9293f158
......@@ -1058,6 +1058,16 @@ insertion_date value_date
2015-01-04 04:00:00+00:00 4.0
2015-01-04 05:00:00+00:00 5.0
2015-01-04 06:00:00+00:00 6.0
""", deltas)
deltas = tsh.get_delta(engine, 'repu2', delta=timedelta(hours=3),
from_value_date=datetime(2015,1,2),
to_value_date=datetime(2015, 1,3))
assert_df("""
2015-01-02 03:00:00+00:00 3.0
2015-01-02 04:00:00+00:00 4.0
2015-01-02 05:00:00+00:00 5.0
2015-01-02 06:00:00+00:00 6.0
""", deltas)
# which is basically the same as below
......
......@@ -189,12 +189,16 @@ class TimeSerie(SeriesServices):
serie.name = seriename
return serie
def get_delta(self, cn, seriename, delta):
def get_delta(self, cn, seriename, delta,
from_value_date=None,
to_value_date=None):
histo = self.get_history(
cn, seriename, deltabefore=-delta
)
df = histo.reset_index()
# df_date is a dataframe with two columns: value_date and insertion_date
df_date = df.loc[:, ['insertion_date', 'value_date']]
......@@ -219,7 +223,7 @@ class TimeSerie(SeriesServices):
# we only keep the value_date information from the index
ts_select.index = new_index
return ts_select
return subset(ts_select, from_value_date, to_value_date)
def exists(self, cn, seriename):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment