Upgrade black

This commit is contained in:
Alexander Hess 2026-11-25 10:24:07 +01:00
commit dbdce83067
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
4 changed files with 1208 additions and 914 deletions

View file

@ -57,7 +57,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 0 # noqa:WPS507 sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -65,7 +66,11 @@ class TestAggregateOrders:
assert len(result) == 0 # noqa:WPS507
def test_evenly_distributed_ad_hoc_orders(
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""12 ad-hoc orders, one per operating hour."""
# Create one order per hour and 12 orders in total.
@ -82,7 +87,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 12 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -94,7 +100,11 @@ class TestAggregateOrders:
assert result['n_orders'].sum() == 12
def test_evenly_distributed_ad_hoc_orders_with_no_demand_late( # noqa:WPS218
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""10 ad-hoc orders, one per hour, no orders after 21."""
# Create one order per hour and 10 orders in total.
@ -111,7 +121,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 10 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -125,7 +136,11 @@ class TestAggregateOrders:
assert result.iloc[10:]['n_orders'].sum() == 0
def test_one_ad_hoc_order_every_other_hour(
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""6 ad-hoc orders, one every other hour."""
# Create one order every other hour.
@ -142,7 +157,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 6 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -154,7 +170,11 @@ class TestAggregateOrders:
assert result['n_orders'].sum() == 6
def test_one_ad_hoc_and_one_pre_order(
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""1 ad-hoc and 1 scheduled order.
@ -180,7 +200,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 2 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -192,7 +213,11 @@ class TestAggregateOrders:
assert result['n_orders'].sum() == 1
def test_evenly_distributed_ad_hoc_orders_with_half_hour_time_steps( # noqa:WPS218
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""12 ad-hoc orders, one per hour, with 30 minute time windows.
@ -212,7 +237,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 12 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.SHORT_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.SHORT_TIME_STEP,
)
result = oh.aggregate_orders()
@ -226,7 +252,11 @@ class TestAggregateOrders:
assert result.iloc[1::2]['n_orders'].sum() == 0
def test_ad_hoc_orders_over_two_days(
self, db_session, one_pixel_grid, restaurant, make_order,
self,
db_session,
one_pixel_grid,
restaurant,
make_order,
):
"""First day 12 ad-hoc orders, one per operating hour ...
@ -262,7 +292,8 @@ class TestAggregateOrders:
assert len(restaurant.orders) == 18 # sanity check
oh = timify.OrderHistory(
grid=one_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=one_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()
@ -275,7 +306,12 @@ class TestAggregateOrders:
@pytest.fixture
def two_pixel_grid( # noqa:WPS211
self, db_session, city, make_address, make_restaurant, addresses_mock,
self,
db_session,
city,
make_address,
make_restaurant,
addresses_mock,
):
"""A persisted `Grid` with two `Pixel` objects."""
# One `Address` in the lower-left `Pixel`, ...
@ -301,7 +337,10 @@ class TestAggregateOrders:
return grid
def test_two_pixels_with_shifted_orders( # noqa:WPS218
self, db_session, two_pixel_grid, make_order,
self,
db_session,
two_pixel_grid,
make_order,
):
"""One restaurant with one order every other hour ...
@ -356,7 +395,8 @@ class TestAggregateOrders:
assert len(restaurant2.orders) == 24
oh = timify.OrderHistory(
grid=two_pixel_grid, time_step=test_config.LONG_TIME_STEP,
grid=two_pixel_grid,
time_step=test_config.LONG_TIME_STEP,
)
result = oh.aggregate_orders()

View file

@ -16,7 +16,10 @@ class TestAverageDailyDemand:
"""Tests for the `OrderHistory.avg_daily_demand()` method."""
def test_avg_daily_demand_with_constant_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""The average daily demand must be the number of time steps ...
@ -34,7 +37,10 @@ class TestAverageDailyDemand:
assert result == 12.0
def test_avg_daily_demand_with_no_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""Without demand, the average daily demand must be `0.0`."""
order_history._data.loc[:, 'n_orders'] = 0
@ -52,7 +58,10 @@ class TestChooseTacticalModel:
"""Tests for the `OrderHistory.choose_tactical_model()` method."""
def test_best_model_with_high_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""With high demand, the average daily demand is `.>= 25.0`."""
# With 12 time steps per day, the ADD becomes `36.0`.
@ -67,7 +76,10 @@ class TestChooseTacticalModel:
assert isinstance(result, models.HorizontalETSModel)
def test_best_model_with_medium_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""With medium demand, the average daily demand is `>= 10.0` and `< 25.0`."""
# With 12 time steps per day, the ADD becomes `24.0`.
@ -82,7 +94,10 @@ class TestChooseTacticalModel:
assert isinstance(result, models.HorizontalETSModel)
def test_best_model_with_low_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""With low demand, the average daily demand is `>= 2.5` and `< 10.0`."""
# With 12 time steps per day, the ADD becomes `12.0` ...
@ -115,7 +130,10 @@ class TestChooseTacticalModel:
assert isinstance(result, models.HorizontalSMAModel)
def test_best_model_with_no_demand(
self, order_history, good_pixel_id, predict_at,
self,
order_history,
good_pixel_id,
predict_at,
):
"""Without demand, the average daily demand is `< 2.5`."""
order_history._data.loc[:, 'n_orders'] = 0
@ -129,7 +147,10 @@ class TestChooseTacticalModel:
assert isinstance(result, models.TrivialModel)
def test_best_model_for_unknown_train_horizon(
self, order_history, good_pixel_id, predict_at, # noqa:RST215
self,
order_history,
good_pixel_id,
predict_at, # noqa:RST215
):
"""For `train_horizon` values not included in the rule-based system ...

View file

@ -38,7 +38,11 @@ def bad_predict_at():
"""
predict_day = test_config.END - datetime.timedelta(weeks=6, days=1)
return datetime.datetime(
predict_day.year, predict_day.month, predict_day.day, test_config.NOON, 0,
predict_day.year,
predict_day.month,
predict_day.day,
test_config.NOON,
0,
)
@ -57,7 +61,11 @@ class TestMakeHorizontalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The time series come as a `pd.Series`."""
result = order_history.make_horizontal_ts(
@ -75,7 +83,11 @@ class TestMakeHorizontalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The length of a training time series must be a multiple of `7` ...
@ -94,7 +106,11 @@ class TestMakeHorizontalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_frequency_is_number_of_weekdays(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The `frequency` must be `7`."""
result = order_history.make_horizontal_ts(
@ -109,7 +125,11 @@ class TestMakeHorizontalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
bad_predict_at,
train_horizon,
):
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
@ -123,7 +143,10 @@ class TestMakeHorizontalTimeSeries:
)
def test_no_long_enough_history2(
self, order_history, good_pixel_id, good_predict_at,
self,
order_history,
good_pixel_id,
good_predict_at,
):
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
@ -131,7 +154,9 @@ class TestMakeHorizontalTimeSeries:
"""
with pytest.raises(RuntimeError):
order_history.make_horizontal_ts(
pixel_id=good_pixel_id, predict_at=good_predict_at, train_horizon=999,
pixel_id=good_pixel_id,
predict_at=good_predict_at,
train_horizon=999,
)
@ -150,7 +175,11 @@ class TestMakeVerticalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The time series come as `pd.Series`."""
result = order_history.make_vertical_ts(
@ -168,7 +197,11 @@ class TestMakeVerticalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The length of a training time series is the product of the ...
@ -197,7 +230,11 @@ class TestMakeVerticalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_frequency_is_number_number_of_weekly_time_steps(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The `frequency` is the number of weekly time steps."""
result = order_history.make_vertical_ts(
@ -218,7 +255,11 @@ class TestMakeVerticalTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
bad_predict_at,
train_horizon,
):
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
@ -232,7 +273,10 @@ class TestMakeVerticalTimeSeries:
)
def test_no_long_enough_history2(
self, order_history, good_pixel_id, good_predict_at,
self,
order_history,
good_pixel_id,
good_predict_at,
):
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
@ -261,7 +305,11 @@ class TestMakeRealTimeTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The time series come as `pd.Series`."""
result = order_history.make_realtime_ts(
@ -279,7 +327,11 @@ class TestMakeRealTimeTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length1(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The length of a training time series is the product of the ...
@ -297,7 +349,9 @@ class TestMakeRealTimeTimeSeries:
0,
)
result = order_history.make_realtime_ts(
pixel_id=good_pixel_id, predict_at=predict_at, train_horizon=train_horizon,
pixel_id=good_pixel_id,
predict_at=predict_at,
train_horizon=train_horizon,
)
training_ts, _, actuals_ts = result
@ -313,7 +367,11 @@ class TestMakeRealTimeTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length2(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The length of a training time series is the product of the ...
@ -352,7 +410,11 @@ class TestMakeRealTimeTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_frequency_is_number_number_of_weekly_time_steps(
self, order_history, good_pixel_id, good_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
good_predict_at,
train_horizon,
):
"""The `frequency` is the number of weekly time steps."""
result = order_history.make_realtime_ts(
@ -373,7 +435,11 @@ class TestMakeRealTimeTimeSeries:
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self, order_history, good_pixel_id, bad_predict_at, train_horizon,
self,
order_history,
good_pixel_id,
bad_predict_at,
train_horizon,
):
"""If the `predict_at` day is too early in the `START`-`END` horizon ...
@ -387,7 +453,10 @@ class TestMakeRealTimeTimeSeries:
)
def test_no_long_enough_history2(
self, order_history, good_pixel_id, good_predict_at,
self,
order_history,
good_pixel_id,
good_predict_at,
):
"""If the `train_horizon` is longer than the `START`-`END` horizon ...
@ -395,5 +464,7 @@ class TestMakeRealTimeTimeSeries:
"""
with pytest.raises(RuntimeError):
order_history.make_realtime_ts(
pixel_id=good_pixel_id, predict_at=good_predict_at, train_horizon=999,
pixel_id=good_pixel_id,
predict_at=good_predict_at,
train_horizon=999,
)

View file

@ -73,7 +73,8 @@ class TestMethods:
def test_first_order_at_non_existing_pixel(self, order_history, good_pixel_id):
"""Test `OrderHistory.first_order_at()` with bad input."""
with pytest.raises(
LookupError, match='`pixel_id` is not in the `grid`',
LookupError,
match='`pixel_id` is not in the `grid`',
):
order_history.first_order_at(-1)
@ -87,6 +88,7 @@ class TestMethods:
def test_last_order_at_non_existing_pixel(self, order_history, good_pixel_id):
"""Test `OrderHistory.last_order_at()` with bad input."""
with pytest.raises(
LookupError, match='`pixel_id` is not in the `grid`',
LookupError,
match='`pixel_id` is not in the `grid`',
):
order_history.last_order_at(-1)