Use double quotes

This commit is contained in:
Alexander Hess 2026-11-28 03:08:55 +01:00
commit ea8f1a13e3
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
4 changed files with 2464 additions and 2466 deletions

View file

@ -29,7 +29,7 @@ class TestAggregateOrders:
query = (
mock.query.return_value.join.return_value.filter.return_value.all # noqa:E501
)
monkeypatch.setattr(db, 'session', mock)
monkeypatch.setattr(db, "session", mock)
return query
@ -95,9 +95,9 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 12 rows holding `1`s.
assert len(result) == 12
assert result['n_orders'].min() == 1
assert result['n_orders'].max() == 1
assert result['n_orders'].sum() == 12
assert result["n_orders"].min() == 1
assert result["n_orders"].max() == 1
assert result["n_orders"].sum() == 12
def test_evenly_distributed_ad_hoc_orders_with_no_demand_late(
self,
@ -130,10 +130,10 @@ class TestAggregateOrders:
# Even though there are only 10 orders, there are 12 rows in the `DataFrame`.
# That is so as `0`s are filled in for hours without any demand at the end.
assert len(result) == 12
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 1
assert result.iloc[:10]['n_orders'].sum() == 10
assert result.iloc[10:]['n_orders'].sum() == 0
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1
assert result.iloc[:10]["n_orders"].sum() == 10
assert result.iloc[10:]["n_orders"].sum() == 0
def test_one_ad_hoc_order_every_other_hour(
self,
@ -165,9 +165,9 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 12 rows, 6 holding `0`s, and 6 holding `1`s.
assert len(result) == 12
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 1
assert result['n_orders'].sum() == 6
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1
assert result["n_orders"].sum() == 6
def test_one_ad_hoc_and_one_pre_order(
self,
@ -208,9 +208,9 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 12 rows, 11 holding `0`s, and one holding a `1`.
assert len(result) == 12
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 1
assert result['n_orders'].sum() == 1
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1
assert result["n_orders"].sum() == 1
def test_evenly_distributed_ad_hoc_orders_with_half_hour_time_steps(
self,
@ -246,10 +246,10 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 24 rows for the 24 30-minute time steps.
# The rows' values are `0` and `1` alternating.
assert len(result) == 24
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 1
assert result.iloc[::2]['n_orders'].sum() == 12
assert result.iloc[1::2]['n_orders'].sum() == 0
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1
assert result.iloc[::2]["n_orders"].sum() == 12
assert result.iloc[1::2]["n_orders"].sum() == 0
def test_ad_hoc_orders_over_two_days(
self,
@ -300,9 +300,9 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 24 rows, 12 for each day.
assert len(result) == 24
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 1
assert result['n_orders'].sum() == 18
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 1
assert result["n_orders"].sum() == 18
@pytest.fixture
def two_pixel_grid(
@ -403,6 +403,6 @@ class TestAggregateOrders:
# The resulting `DataFrame` has 24 rows, 12 for each pixel.
assert len(result) == 24
assert result['n_orders'].min() == 0
assert result['n_orders'].max() == 2
assert result['n_orders'].sum() == 30
assert result["n_orders"].min() == 0
assert result["n_orders"].max() == 2
assert result["n_orders"].sum() == 30

View file

@ -43,7 +43,7 @@ class TestAverageDailyDemand:
predict_at,
):
"""Without demand, the average daily demand must be `0.0`."""
order_history._data.loc[:, 'n_orders'] = 0
order_history._data.loc[:, "n_orders"] = 0
result = order_history.avg_daily_demand(
pixel_id=good_pixel_id,
@ -65,7 +65,7 @@ class TestChooseTacticalModel:
):
"""With high demand, the average daily demand is `.>= 25.0`."""
# With 12 time steps per day, the ADD becomes `36.0`.
order_history._data.loc[:, 'n_orders'] = 3
order_history._data.loc[:, "n_orders"] = 3
result = order_history.choose_tactical_model(
pixel_id=good_pixel_id,
@ -83,7 +83,7 @@ class TestChooseTacticalModel:
):
"""With medium demand, the average daily demand is `>= 10.0` and `< 25.0`."""
# With 12 time steps per day, the ADD becomes `24.0`.
order_history._data.loc[:, 'n_orders'] = 2
order_history._data.loc[:, "n_orders"] = 2
result = order_history.choose_tactical_model(
pixel_id=good_pixel_id,
@ -102,23 +102,23 @@ class TestChooseTacticalModel:
"""With low demand, the average daily demand is `>= 2.5` and `< 10.0`."""
# With 12 time steps per day, the ADD becomes `12.0` ...
data = order_history._data
data.loc[:, 'n_orders'] = 1
data.loc[:, "n_orders"] = 1
# ... and we set three additional time steps per day to `0`.
data.loc[
# all `Pixel`s, all `Order`s in time steps starting at 11 am
(slice(None), slice(data.index.levels[1][0], None, 12)),
'n_orders',
"n_orders",
] = 0
data.loc[
# all `Pixel`s, all `Order`s in time steps starting at 12 am
(slice(None), slice(data.index.levels[1][1], None, 12)),
'n_orders',
"n_orders",
] = 0
data.loc[
# all `Pixel`s, all `Order`s in time steps starting at 1 pm
(slice(None), slice(data.index.levels[1][2], None, 12)),
'n_orders',
"n_orders",
] = 0
result = order_history.choose_tactical_model(
@ -136,7 +136,7 @@ class TestChooseTacticalModel:
predict_at,
):
"""Without demand, the average daily demand is `< 2.5`."""
order_history._data.loc[:, 'n_orders'] = 0
order_history._data.loc[:, "n_orders"] = 0
result = order_history.choose_tactical_model(
pixel_id=good_pixel_id,
@ -156,7 +156,7 @@ class TestChooseTacticalModel:
... the method raises a `RuntimeError`.
"""
with pytest.raises(RuntimeError, match='no rule'):
with pytest.raises(RuntimeError, match="no rule"):
order_history.choose_tactical_model(
pixel_id=good_pixel_id,
predict_day=predict_at.date(),

View file

@ -49,7 +49,7 @@ def bad_predict_at():
class TestMakeHorizontalTimeSeries:
"""Test the `OrderHistory.make_horizontal_ts()` method."""
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_wrong_pixel(self, order_history, good_predict_at, train_horizon):
"""A `pixel_id` that is not in the `grid`."""
with pytest.raises(LookupError):
@ -59,7 +59,7 @@ class TestMakeHorizontalTimeSeries:
train_horizon=train_horizon,
)
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self,
order_history,
@ -77,11 +77,11 @@ class TestMakeHorizontalTimeSeries:
training_ts, _, actuals_ts = result
assert isinstance(training_ts, pd.Series)
assert training_ts.name == 'n_orders'
assert training_ts.name == "n_orders"
assert isinstance(actuals_ts, pd.Series)
assert actuals_ts.name == 'n_orders'
assert actuals_ts.name == "n_orders"
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length(
self,
order_history,
@ -104,7 +104,7 @@ class TestMakeHorizontalTimeSeries:
assert len(training_ts) == 7 * train_horizon
assert len(actuals_ts) == 1
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_frequency_is_number_of_weekdays(
self,
order_history,
@ -123,7 +123,7 @@ class TestMakeHorizontalTimeSeries:
assert frequency == 7
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self,
order_history,
@ -163,7 +163,7 @@ class TestMakeHorizontalTimeSeries:
class TestMakeVerticalTimeSeries:
"""Test the `OrderHistory.make_vertical_ts()` method."""
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_wrong_pixel(self, order_history, good_predict_at, train_horizon):
"""A `pixel_id` that is not in the `grid`."""
with pytest.raises(LookupError):
@ -173,7 +173,7 @@ class TestMakeVerticalTimeSeries:
train_horizon=train_horizon,
)
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self,
order_history,
@ -191,11 +191,11 @@ class TestMakeVerticalTimeSeries:
training_ts, _, actuals_ts = result
assert isinstance(training_ts, pd.Series)
assert training_ts.name == 'n_orders'
assert training_ts.name == "n_orders"
assert isinstance(actuals_ts, pd.Series)
assert actuals_ts.name == 'n_orders'
assert actuals_ts.name == "n_orders"
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length(
self,
order_history,
@ -228,7 +228,7 @@ class TestMakeVerticalTimeSeries:
assert len(training_ts) == 7 * n_daily_time_steps * train_horizon
assert len(actuals_ts) == n_daily_time_steps
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_frequency_is_number_number_of_weekly_time_steps(
self,
order_history,
@ -253,7 +253,7 @@ class TestMakeVerticalTimeSeries:
assert frequency == 7 * n_daily_time_steps
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self,
order_history,
@ -293,7 +293,7 @@ class TestMakeVerticalTimeSeries:
class TestMakeRealTimeTimeSeries:
"""Test the `OrderHistory.make_realtime_ts()` method."""
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_wrong_pixel(self, order_history, good_predict_at, train_horizon):
"""A `pixel_id` that is not in the `grid`."""
with pytest.raises(LookupError):
@ -303,7 +303,7 @@ class TestMakeRealTimeTimeSeries:
train_horizon=train_horizon,
)
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_are_series(
self,
order_history,
@ -321,11 +321,11 @@ class TestMakeRealTimeTimeSeries:
training_ts, _, actuals_ts = result
assert isinstance(training_ts, pd.Series)
assert training_ts.name == 'n_orders'
assert training_ts.name == "n_orders"
assert isinstance(actuals_ts, pd.Series)
assert actuals_ts.name == 'n_orders'
assert actuals_ts.name == "n_orders"
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length1(
self,
order_history,
@ -365,7 +365,7 @@ class TestMakeRealTimeTimeSeries:
assert len(training_ts) == 7 * n_daily_time_steps * train_horizon
assert len(actuals_ts) == 1
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_time_series_have_correct_length2(
self,
order_history,
@ -408,7 +408,7 @@ class TestMakeRealTimeTimeSeries:
)
assert len(actuals_ts) == 1
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_frequency_is_number_number_of_weekly_time_steps(
self,
order_history,
@ -433,7 +433,7 @@ class TestMakeRealTimeTimeSeries:
assert frequency == 7 * n_daily_time_steps
@pytest.mark.parametrize('train_horizon', test_config.TRAIN_HORIZONS)
@pytest.mark.parametrize("train_horizon", test_config.TRAIN_HORIZONS)
def test_no_long_enough_history1(
self,
order_history,

View file

@ -19,7 +19,7 @@ class TestSpecialMethods:
class TestProperties:
"""Test the properties in `OrderHistory`."""
@pytest.mark.parametrize('time_step', test_config.TIME_STEPS)
@pytest.mark.parametrize("time_step", test_config.TIME_STEPS)
def test_time_step(self, grid, time_step):
"""Test `OrderHistory.time_step` property."""
order_history = timify.OrderHistory(grid=grid, time_step=time_step)
@ -50,9 +50,9 @@ class TestProperties:
Note: We make `OrderHistory.aggregate_orders()` return a `sentinel`
that is cached into `OrderHistory._data`, which must be unset first.
"""
monkeypatch.setattr(order_history, '_data', None)
monkeypatch.setattr(order_history, "_data", None)
sentinel = object()
monkeypatch.setattr(order_history, 'aggregate_orders', lambda: sentinel)
monkeypatch.setattr(order_history, "aggregate_orders", lambda: sentinel)
result1 = order_history.totals
result2 = order_history.totals
@ -74,7 +74,7 @@ class TestMethods:
"""Test `OrderHistory.first_order_at()` with bad input."""
with pytest.raises(
LookupError,
match='`pixel_id` is not in the `grid`',
match="`pixel_id` is not in the `grid`",
):
order_history.first_order_at(-1)
@ -89,6 +89,6 @@ class TestMethods:
"""Test `OrderHistory.last_order_at()` with bad input."""
with pytest.raises(
LookupError,
match='`pixel_id` is not in the `grid`',
match="`pixel_id` is not in the `grid`",
):
order_history.last_order_at(-1)