DtsServer fails to evaluate expression with .extend
Overview
Given a slightly modified example from @ole.andreas.ramsdal , this one fails to evaluate (with exception thrown from the dtss server, that during evaluation, there was a misaligned time-axis,values attempt:
# to be run by pytest
from pathlib import Path
from typing import Tuple
from shyft.time_series import TsVector, TimeSeries, TimeAxis, time, Calendar, DtsServer, DtsClient
from shyft.time_series import shyft_url, POINT_AVERAGE_VALUE
def start_dts_server(dtss_root_dir) -> Tuple[DtsServer, DtsClient]:
dtss_host = '127.0.0.1'
container_dir = dtss_root_dir / Path('stm')
if not dtss_root_dir.is_dir():
dtss_root_dir.mkdir()
if not container_dir.is_dir():
container_dir.mkdir()
dts_server = DtsServer()
dts_server.set_container('stm', str(container_dir))
dtss_port = dts_server.start_server() # notice we get a safe to use auto port here
dts_client = DtsClient(f"{dtss_host}:{dtss_port}", 1000)
return dts_server, dts_client
def test_dtss_extend_case(tmp_path):
ta_to_extend = TimeAxis(time("2022-01-01T00:00:00Z"), Calendar.HOUR, 3)
ta_other = TimeAxis(time("2022-01-03T00:00:00Z"), Calendar.HOUR, 3)
to_extend_ts = TimeSeries(ta_to_extend, [1, 2, 3], POINT_AVERAGE_VALUE)
to_extend_ts = TimeSeries(shyft_url("stm", "a"), to_extend_ts)
ts_other = TimeSeries(ta_other, [4, 5, 6], POINT_AVERAGE_VALUE)
ts_other = TimeSeries(shyft_url("stm", "b"), ts_other)
eval_ts = TimeSeries(shyft_url("stm", "a")).extend(TimeSeries(shyft_url("stm", "b")))
tmp_dir = tmp_path/"dtss"
srv, cli = start_dts_server(tmp_dir)
cli.store_ts(TsVector([to_extend_ts, ts_other]))
cli.evaluate(TsVector([eval_ts]), ta_other.total_period())
srv.stop_server()
The expected value, in this case, would be like 'b' series. The read-period supplied to the evaluator, including the expression, is not sufficient to provide values from 'a'.
The bug is that the internal logic for evaluation (regardless missing length of period of evaluation), caused a state that was caught by the internal time-series constructor guard, and in general we would try to enforce that
a = _some_ts_expression
e = a.evaluate() # this will flatten out the expression and give the evaluated replica ts as a concrete time-series(terminal)
assert a == e
Edited by Sigbjørn Helset