Commit 9fb28ab2 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

delta: fix crash on empty history

get_history: we distinguish "no history" from "no such series"
get_delta: we now don't crash on empty history
parent a303867922a8
......@@ -685,7 +685,7 @@ insertion_date value_date
tsc = tsh.get_history(engine, 'smallserie',
from_insertion_date=datetime(2017, 2, 4),
to_insertion_date=datetime(2017, 2, 4))
assert tsc is None
assert tsc == {}
tsc = tsh.get_history(engine, 'smallserie',
from_insertion_date=datetime(2016, 2, 1),
......@@ -700,7 +700,7 @@ insertion_date value_date
tsc = tsh.get_history(engine, 'smallserie',
from_insertion_date=datetime(2016, 2, 1),
to_insertion_date=datetime(2016, 12, 31))
assert tsc is None
assert tsc == {}
# restrictions on value dates
tsc = tsh.get_history(engine, 'smallserie',
......@@ -735,6 +735,9 @@ insertion_date value_date
2017-01-02 1.0
""", tsc)
tsc = tsh.get_history(engine, 'no-such-series')
assert tsc is None
def test_history_delta(engine, tsh):
for d in range(1, 3):
......@@ -1195,12 +1198,13 @@ insertion_date value_date
2015-01-03 04:00:00+00:00 4.0
""", deltas)
# exhibit issue with out-of-bounds from/to constraint
with pytest.raises(AttributeError):
deltas = tsh.get_delta(engine, 'repu2',
delta=timedelta(hours=3),
from_value_date=utcdt(2014, 1, 1, 6),
to_value_date=utcdt(2014, 1, 3, 4))
# out-of-bounds from/to constraint
deltas = tsh.get_delta(engine, 'repu2',
delta=timedelta(hours=3),
from_value_date=utcdt(2014, 1, 1, 6),
to_value_date=utcdt(2014, 1, 3, 4))
assert len(deltas) == 0
assert isinstance(deltas, pd.Series)
def test_rename(engine, tsh):
......
......@@ -172,7 +172,7 @@ class TimeSerie(SeriesServices):
{'fromdate': from_value_date, 'todate': to_value_date}
).fetchall()
if not revs:
return
return {}
if diffmode:
# compute the previous serie value
......
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