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

history: prune successive items showing no difference

parent 106e7570b1bc
......@@ -774,8 +774,6 @@ insertion_date value_date
2017-02-01 00:00:00+00:00 2017-01-01 0.0
2017-02-02 00:00:00+00:00 2017-01-01 0.0
2017-01-02 1.0
2017-02-03 00:00:00+00:00 2017-01-01 0.0
2017-01-02 1.0
""", tsc)
tsc = tsh.history(engine, 'smallserie',
......@@ -794,8 +792,6 @@ insertion_date value_date
2017-02-01 00:00:00+00:00 2017-01-01 0.0
2017-02-02 00:00:00+00:00 2017-01-01 0.0
2017-01-02 1.0
2017-02-03 00:00:00+00:00 2017-01-01 0.0
2017-01-02 1.0
""", tsc)
tsc = tsh.history(engine, 'no-such-series')
......
......@@ -14,6 +14,7 @@ from sqlhelp import sqlfile, select
from tshistory.util import (
closed_overlaps,
num2float,
pruned_history,
SeriesServices,
start_end,
tx,
......@@ -255,11 +256,19 @@ class timeseries(SeriesServices):
for idate, ts in series
]
return {
hist = {
idate: ts
for idate, ts in series if len(series)
}
if from_value_date or to_value_date:
# now it's possible that the extremities cut
# yields similar series for successive idates
# and we are not interested in that
hist = pruned_history(hist)
return hist
@tx
def staircase(self, cn, seriename, delta,
from_value_date=None,
......
......@@ -66,6 +66,23 @@ def tzaware_serie(ts):
return is_datetime64tz_dtype(ts.index)
def pruned_history(hist):
if not hist:
return hist
idates = list(hist.keys())
idate = idates[0]
current = hist[idate]
pruned = {
idate: current
}
for idate in idates[1:]:
newts = hist[idate]
if not current.equals(newts):
pruned[idate] = newts
current = newts
return pruned
def start_end(ts, notz=True):
ts = ts.dropna()
if not len(ts):
......
Markdown is supported
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