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

staircase: make it simpler

We get the base dates from the current series value dates.
For each of those we query one point, then concatenate
the result.

Conceptually much simpler to grasp.
Bonus side effect: staircase discrepencies of formula vs alias
extensions have disappeared.

Performance implications:

base:
DELTA all value dates 0.9304628372192383
DELTA 1 day  0.10948061943054199

correctness:
DELTA all value dates 1.174530267715454
DELTA 1 day  0.05773115158081055

So on the whole horizon we are a tad slower but there is an
interesting speedup already in a well-bounded case. This is not bad.
parent 535fbd69b86d
......@@ -286,26 +286,32 @@ class timeseries(SeriesServices):
`delta` time after the insertion dates and where we
keep the most recent ones
"""
histo = self.history(
cn, seriename, deltabefore=-delta,
if not self.exists(cn, seriename):
return
base = self.get(
cn, seriename,
from_value_date=from_value_date,
to_value_date=to_value_date,
_keep_nans=True
to_value_date=to_value_date
)
if histo is None:
return None
vimap = {}
vvmap = {}
for idate, series in histo.items():
for vdate, value in series.iteritems():
if vdate not in vimap or vimap[vdate] < idate:
vimap[vdate] = idate
vvmap[vdate] = value
if not len(base):
return base
chunks = []
for vdate in base.index:
ts = self.get(
cn, seriename, revision_date=vdate - delta,
from_value_date=vdate,
to_value_date=vdate
)
if ts is not None and len(ts):
chunks.append(ts)
ts = pd.Series(vvmap).sort_index().loc[from_value_date:to_value_date]
ts = pd.Series()
if chunks:
ts = pd.concat(chunks)
ts.name = seriename
return ts.dropna()
return ts
def exists(self, cn, seriename):
return self._serie_to_tablename(cn, seriename) is not None
......
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