Skip to content

Commit 54e20e8

Browse files
committed
Reduce number of windows by one in WindowedForecast
This is a partial revert of c08a256 that added one to the number of windows to ensure that for low durations the number of windows is the same as the number of data points. While this fixed errors for durations close to 48h, it introduced #119 that caused errors for low durations (5 min). This is caused by the interpolation trying to read past the last data frame. Fixes: #119
1 parent db2d346 commit 54e20e8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cats/forecast.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def bisect_left(data, t):
6767
for i, d in enumerate(data):
6868
if d.datetime + self.data_stepsize >= t:
6969
return i + 1
70+
raise ValueError("No index found for closest data point past job end time")
7071

7172
self.ndata = bisect_left(self.data, self.end) # window size
7273

@@ -147,4 +148,4 @@ def __iter__(self):
147148
yield self.__getitem__(index)
148149

149150
def __len__(self):
150-
return len(self.data) - self.ndata + 1
151+
return len(self.data) - self.ndata

tests/test_windowed_forecast.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_has_right_length():
5353

5454
# Expecting (200 - 160 + 1) (41) data points in the time
5555
# integrated timeseries.
56-
assert len(wf) == NDATA - window_size + 1
56+
assert len(wf) == NDATA - window_size
5757

5858

5959
def test_values():
@@ -67,7 +67,7 @@ def test_values():
6767
wf = WindowedForecast(DATA, window_size, start=DATA[0].datetime)
6868
expected = [
6969
math.cos((i + window_size) * step) - math.cos(i * step)
70-
for i in range(len(DATA) - window_size + 1)
70+
for i in range(len(DATA) - window_size)
7171
]
7272
# average
7373
expected = [e / (window_size * step) for e in expected]

0 commit comments

Comments
 (0)