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

snapshot: definitely retire build_up_to

We now maintain a robust snapshot at each changeset,
this is unneeded.
parent 2082c0791eac
......@@ -335,7 +335,7 @@ def test_deletion(engine, tsh):
ts_begin.iloc[-1] = np.nan
tsh.insert(engine, ts_begin, 'ts_del', 'test')
ts = Snapshot(engine, tsh, 'ts_del').build_upto()
_, ts = Snapshot(engine, tsh, 'ts_del').find()
assert ts.iloc[-1] == 9.0
ts_begin.iloc[0] = np.nan
......
......@@ -176,41 +176,3 @@ class Snapshot(SeriesServices):
chunk = self.chunk(cid, from_value_date, to_value_date)
return csid, chunk
def build_upto(self, qfilter=(),
from_value_date=None, to_value_date=None):
csid, snapshot = self.find(qfilter,
from_value_date=from_value_date,
to_value_date=to_value_date)
if csid is None:
return
cset = self.tsh.schema.changeset
table = self.tsh._get_ts_table(self.cn, self.name)
sql = select([table.c.id,
table.c.diff,
cset.c.insertion_date]
).order_by(table.c.id
).where(table.c.cset > csid
).where(table.c.cset == cset.c.id)
if qfilter:
for filtercb in qfilter:
sql = sql.where(filtercb(cset, table))
alldiffs = self.cn.execute(sql).fetchall()
if not len(alldiffs):
return snapshot
# initial ts
ts = self._deserialize(alldiffs[0].diff, self.name)
ts = self.tsh._ensure_tz_consistency(self.cn, ts)
for row in alldiffs[1:]:
diff = subset(self._deserialize(row.diff, self.name),
from_value_date, to_value_date)
diff = self.tsh._ensure_tz_consistency(self.cn, diff)
ts = self.patch(ts, diff)
ts = self.patch(snapshot, ts)
assert ts.index.dtype.name == 'datetime64[ns]' or len(ts) == 0
return ts
......@@ -78,9 +78,9 @@ class TimeSerie(SeriesServices):
if revision_date:
qfilter.append(lambda cset, _: cset.c.insertion_date <= revision_date)
snap = Snapshot(cn, self, name)
current = snap.build_upto(qfilter,
from_value_date=from_value_date,
to_value_date=to_value_date)
_, current = snap.find(qfilter,
from_value_date=from_value_date,
to_value_date=to_value_date)
if current is not None and not _keep_nans:
current.name = name
......@@ -143,8 +143,8 @@ class TimeSerie(SeriesServices):
csid, revdate, diff_ = diffs[0]
snap = Snapshot(cn, self, name)
snapshot = snap.build_upto([lambda cset, _: cset.c.id <= csid],
from_value_date, to_value_date)
_, snapshot = snap.find([lambda cset, _: cset.c.id <= csid],
from_value_date, to_value_date)
series = [(revdate, subset(snapshot, from_value_date, to_value_date))]
for csid_, revdate, diff in diffs[1:]:
......
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