You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case where I need to change the value of a timeseries on an interval without changing the value outside of the interval, ie do something like ts[start:end] = value.
Just setting
ts[end] =ts[end] # freezing/anchoring the current value of ts as of [end, ...)ts[start] =value# changing the value as of [start, ...)
may fail as intermediate points in [start,end) may exist ==> we need to remove all intermediate points (which is easy as ts.iterperiods(start,end) provides them nicely).
I think the function below does it properly (but it would be better integrated in the item to use the slice notation)
defset_slice(ts, start, end, value):
""" ts[start:end] = value ==> call set_slice(ts, start, end, value) Set the value of the ts so that - on the interval [start, end) we have the new value - on [end, ...) we haven't change the value - on (..., start) we haven't change the value neither We replace the value of the ts on an interval. :param ts: :param start: :param end: :param value: :return: """# for each interval to renderfori, (s, e, v) inenumerate(list(ts.iterperiods(start, end))):
# look at all intervals included in the current interval# (always at least 1)ifi==0:
# if the first, set initial value to new value of rangets[s] =valueelse:
# otherwise, remove intermediate keydelts[s]
# finish by setting the end of the interval to the previous valuets[end] =v
The text was updated successfully, but these errors were encountered:
Good idea! I can see how that could be useful in some cases. I'd welcome a pull request (especially if you write a couple of accompanying tests) — I can also add something like this in, though it might not be for a week or two.
I think it might be good to include a compact=False keyword argument, too, to keep consistent with set and to specify whether the endpoints of the interval will always be included as measurements.
I have a use case where I need to change the value of a timeseries on an interval without changing the value outside of the interval, ie do something like ts[start:end] = value.
Just setting
may fail as intermediate points in [start,end) may exist ==> we need to remove all intermediate points (which is easy as
ts.iterperiods(start,end)
provides them nicely).I think the function below does it properly (but it would be better integrated in the item to use the slice notation)
The text was updated successfully, but these errors were encountered: