Check if predict_at/day
is in .totals
- this is a minor sanity check
This commit is contained in:
parent
f36fffdd4d
commit
0c1ff5338d
3 changed files with 12 additions and 4 deletions
|
@ -145,6 +145,8 @@ per-file-ignores =
|
||||||
src/urban_meal_delivery/forecasts/timify.py:
|
src/urban_meal_delivery/forecasts/timify.py:
|
||||||
# No SQL injection as the inputs come from a safe source.
|
# No SQL injection as the inputs come from a safe source.
|
||||||
S608,
|
S608,
|
||||||
|
# The many noqa's are ok.
|
||||||
|
WPS403,
|
||||||
tests/*.py:
|
tests/*.py:
|
||||||
# Type annotations are not strictly enforced.
|
# Type annotations are not strictly enforced.
|
||||||
ANN0, ANN2,
|
ANN0, ANN2,
|
||||||
|
|
|
@ -99,7 +99,7 @@ def stl( # noqa:C901,WPS210,WPS211,WPS231
|
||||||
if ns % 2 == 0 or ns < 7:
|
if ns % 2 == 0 or ns < 7:
|
||||||
raise ValueError('`ns` must be odd and `>= 7`')
|
raise ValueError('`ns` must be odd and `>= 7`')
|
||||||
|
|
||||||
default_nt = math.ceil((1.5 * frequency) / (1 - (1.5 / ns))) # noqa:WPS432
|
default_nt = math.ceil((1.5 * frequency) / (1 - (1.5 / ns)))
|
||||||
if nt is not None:
|
if nt is not None:
|
||||||
if nt % 2 == 0 or nt < default_nt:
|
if nt % 2 == 0 or nt < default_nt:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
|
@ -168,7 +168,7 @@ class OrderHistory:
|
||||||
training time series, frequency, actual order count at `predict_at`
|
training time series, frequency, actual order count at `predict_at`
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
LookupError: `pixel_id` is not in the `grid`
|
LookupError: `pixel_id` not in `grid` or `predict_at` not in `.totals`
|
||||||
RuntimeError: desired time series slice is not entirely in `.totals`
|
RuntimeError: desired time series slice is not entirely in `.totals`
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -211,6 +211,8 @@ class OrderHistory:
|
||||||
raise RuntimeError('Not enough historic data for `predict_at`')
|
raise RuntimeError('Not enough historic data for `predict_at`')
|
||||||
|
|
||||||
actuals_ts = intra_pixel.loc[[predict_at], 'total_orders']
|
actuals_ts = intra_pixel.loc[[predict_at], 'total_orders']
|
||||||
|
if not len(actuals_ts): # pragma: no cover
|
||||||
|
raise LookupError('`predict_at` is not in the order history')
|
||||||
|
|
||||||
return training_ts, frequency, actuals_ts
|
return training_ts, frequency, actuals_ts
|
||||||
|
|
||||||
|
@ -235,7 +237,7 @@ class OrderHistory:
|
||||||
training time series, frequency, actual order counts on `predict_day`
|
training time series, frequency, actual order counts on `predict_day`
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
LookupError: `pixel_id` is not in the `grid`
|
LookupError: `pixel_id` not in `grid` or `predict_day` not in `.totals`
|
||||||
RuntimeError: desired time series slice is not entirely in `.totals`
|
RuntimeError: desired time series slice is not entirely in `.totals`
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -295,6 +297,8 @@ class OrderHistory:
|
||||||
first_prediction_at:last_prediction_at, # type: ignore
|
first_prediction_at:last_prediction_at, # type: ignore
|
||||||
'total_orders',
|
'total_orders',
|
||||||
]
|
]
|
||||||
|
if not len(actuals_ts): # pragma: no cover
|
||||||
|
raise LookupError('`predict_day` is not in the order history')
|
||||||
|
|
||||||
return training_ts, frequency, actuals_ts
|
return training_ts, frequency, actuals_ts
|
||||||
|
|
||||||
|
@ -319,7 +323,7 @@ class OrderHistory:
|
||||||
training time series, frequency, actual order count at `predict_at`
|
training time series, frequency, actual order count at `predict_at`
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
LookupError: `pixel_id` is not in the `grid`
|
LookupError: `pixel_id` not in `grid` or `predict_at` not in `.totals`
|
||||||
RuntimeError: desired time series slice is not entirely in `.totals`
|
RuntimeError: desired time series slice is not entirely in `.totals`
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
@ -386,5 +390,7 @@ class OrderHistory:
|
||||||
raise RuntimeError('Not enough historic data for `predict_day`')
|
raise RuntimeError('Not enough historic data for `predict_day`')
|
||||||
|
|
||||||
actuals_ts = intra_pixel.loc[[predict_at], 'total_orders']
|
actuals_ts = intra_pixel.loc[[predict_at], 'total_orders']
|
||||||
|
if not len(actuals_ts): # pragma: no cover
|
||||||
|
raise LookupError('`predict_at` is not in the order history')
|
||||||
|
|
||||||
return training_ts, frequency, actuals_ts
|
return training_ts, frequency, actuals_ts
|
||||||
|
|
Loading…
Reference in a new issue