Commit 09a91503 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

tsio: add `from_value_date` and `to_value_date` parameters

parent e4d8f648d348
......@@ -847,6 +847,39 @@ insertion_date value_date
to_insertion_date=datetime(2016, 12, 31))
assert tsc is None
# restrictions on value dates
tsc = tsh.get_history(engine, 'smallserie',
from_value_date=datetime(2017, 1, 1),
to_value_date=datetime(2017, 1, 2))
assert_df("""
insertion_date value_date
2017-02-01 2017-01-01 0.0
2017-02-02 2017-01-01 0.0
2017-01-02 1.0
2017-02-03 2017-01-01 0.0
2017-01-02 1.0
""", tsc)
tsc = tsh.get_history(engine, 'smallserie',
from_value_date=datetime(2017, 1, 2))
assert_df("""
insertion_date value_date
2017-02-02 2017-01-02 1.0
2017-02-03 2017-01-02 1.0
2017-01-03 2.0
""", tsc)
tsc = tsh.get_history(engine, 'smallserie',
to_value_date=datetime(2017, 1, 2))
assert_df("""
insertion_date value_date
2017-02-01 2017-01-01 0.0
2017-02-02 2017-01-01 0.0
2017-01-02 1.0
2017-02-03 2017-01-01 0.0
2017-01-02 1.0
""", tsc)
def test_add_na(engine, tsh):
# a serie of NaNs won't be insert in base
......@@ -1013,3 +1046,21 @@ def test_lots_of_diffs(engine, tracker, ptsh):
'time': t1,
'diffsize': None,
'snapsize': None})
t0 = time()
for month in range(1, 3):
for day in range(1, 5):
date = datetime(2018, month, day)
ts = tsh.get_history(engine, 'manydiffs',
from_insertion_date=date,
to_insertion_date=date+timedelta(days=31),
from_value_date=date+timedelta(days=10),
to_value_date=date+timedelta(days=20))
assert ts is not None
t1 = time() - t0
tracker.append({'test': 'lots_of_diffs_get_history_chunks_valuedate',
'class': tshclass,
'time': t1,
'diffsize': None,
'snapsize': None})
......@@ -192,7 +192,9 @@ class TimeSerie(object):
def get_history(self, cn, name,
from_insertion_date=None,
to_insertion_date=None):
to_insertion_date=None,
from_value_date=None,
to_value_date=None):
table = self._get_ts_table(cn, name)
if table is None:
return
......@@ -233,6 +235,7 @@ class TimeSerie(object):
serie = pd.concat([serie for revdate_, serie in series])
serie.name = name
return serie.loc[:,from_value_date:to_value_date]
return serie
def exists(self, cn, name):
......
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