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): ...@@ -286,26 +286,32 @@ class timeseries(SeriesServices):
`delta` time after the insertion dates and where we `delta` time after the insertion dates and where we
keep the most recent ones keep the most recent ones
""" """
histo = self.history( if not self.exists(cn, seriename):
cn, seriename, deltabefore=-delta, return
base = self.get(
cn, seriename,
from_value_date=from_value_date, from_value_date=from_value_date,
to_value_date=to_value_date, to_value_date=to_value_date
_keep_nans=True
) )
if histo is None: if not len(base):
return None return base
vimap = {} chunks = []
vvmap = {} for vdate in base.index:
for idate, series in histo.items(): ts = self.get(
for vdate, value in series.iteritems(): cn, seriename, revision_date=vdate - delta,
if vdate not in vimap or vimap[vdate] < idate: from_value_date=vdate,
vimap[vdate] = idate to_value_date=vdate
vvmap[vdate] = value )
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 ts.name = seriename
return ts.dropna() return ts
def exists(self, cn, seriename): def exists(self, cn, seriename):
return self._serie_to_tablename(cn, seriename) is not None 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