Avoid queries that may return None
The last `grid` of the loop already belongs to the `city`, and `.scalar()` returns the maximum or `None` without indexing a row
This commit is contained in:
parent
82d245836f
commit
1cc5dcff54
2 changed files with 3 additions and 4 deletions
|
|
@ -112,8 +112,8 @@ def tactical_heuristic( # noqa:C901,D417,DOC001
|
||||||
.filter(db.Grid.side_length == side_length)
|
.filter(db.Grid.side_length == side_length)
|
||||||
.filter(db.Forecast.time_step == time_step)
|
.filter(db.Forecast.time_step == time_step)
|
||||||
.filter(db.Forecast.train_horizon == train_horizon)
|
.filter(db.Forecast.train_horizon == train_horizon)
|
||||||
.first()
|
.scalar()
|
||||||
)[0]
|
)
|
||||||
# ... or start `train_horizon` weeks after the first `Order`
|
# ... or start `train_horizon` weeks after the first `Order`
|
||||||
# if no `Forecast`s are in the database yet.
|
# if no `Forecast`s are in the database yet.
|
||||||
if last_predict_at is None:
|
if last_predict_at is None:
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,7 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
||||||
click.echo(f" -> created {len(grid.pixels)} pixels")
|
click.echo(f" -> created {len(grid.pixels)} pixels")
|
||||||
|
|
||||||
# Because the number of assigned addresses is the same across
|
# Because the number of assigned addresses is the same across
|
||||||
# different `side_length`s, we can take any `grid` from the `city`.
|
# different `side_length`s, we can take the last `grid` from the `city`.
|
||||||
grid = db.session.query(db.Grid).filter_by(city=city).first()
|
|
||||||
n_assigned = (
|
n_assigned = (
|
||||||
db.session.query(db.AddressPixelAssociation)
|
db.session.query(db.AddressPixelAssociation)
|
||||||
.filter(db.AddressPixelAssociation.grid_id == grid.id)
|
.filter(db.AddressPixelAssociation.grid_id == grid.id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue