Skip to content

Commit d80b7e1

Browse files
authored
Merge pull request #148 from UCL-CORU/fix-specialty-mismatch
## Summary - Separate services and subgroups into distinct keys (`"services"` / `"subgroups"`) in the transfer model's internal dict, so subgroup names (e.g. `paediatric`, `adult_male_young`) no longer appear alongside real services in error messages - Return `0.0` with a warning when `get_transfer_prob` is called with a service not in the training set, instead of crashing with a `ValueError` that dumps hundreds of service names - Shorten `warn_specialty_mismatch` messages to report counts only, without listing every mismatched specialty - Add prettier formatting step to `tox -e docs` (pinned to `@3.1.0`) so generated notebook markdown matches the pre-commit hook and doesn't create spurious diffs - Fix task issue template formatting
2 parents 71e4fbf + d0e97f4 commit d80b7e1

7 files changed

Lines changed: 244 additions & 378 deletions

File tree

.github/ISSUE_TEMPLATE/task.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Task
3+
about: A Task to be Completed
4+
labels: task
5+
---

.github/ISSUE_TEMPLATE/task.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ legacy_tox_ini = """
144144
jupyter nbconvert {toxinidir}/notebooks/*.ipynb --to markdown --output-dir={toxinidir}/docs/notebooks
145145
cp {toxinidir}/notebooks/README.md {toxinidir}/docs/notebooks/README.md
146146
python {toxinidir}/docs/notebooks/update_notebook_links.py {toxinidir}/docs/notebooks
147+
npx prettier@3.1.0 --write --quote-props=as-needed {toxinidir}/docs/notebooks/*.md
147148
mkdocs build
148149
extras =
149150
docs
150151
allowlist_externals =
151152
cp
153+
npx
152154
153155
[tox]
154156
env_list =

src/patientflow/predict/emergency_demand.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,13 @@ def warn_specialty_mismatch(
8282
if new_in_request:
8383
warnings.warn(
8484
f"{len(new_in_request)} specialties found in the request but absent "
85-
f"from the trained {source_label} (models may need retraining): "
86-
f"{sorted(new_in_request)}",
85+
f"from the trained {source_label} (models may need retraining).",
8786
stacklevel=stacklevel,
8887
)
8988
if missing_from_request:
9089
warnings.warn(
9190
f"{len(missing_from_request)} specialties present in the trained "
92-
f"{source_label} but absent from the request: "
93-
f"{sorted(missing_from_request)}",
91+
f"{source_label} but absent from the request.",
9492
stacklevel=stacklevel,
9593
)
9694

src/patientflow/predict/service.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,9 @@ def compute_transfer_arrivals(
13571357
f"got {type(source_data)}"
13581358
)
13591359

1360-
# Get transfer probabilities from model
1360+
# Get transfer probabilities from model.
1361+
# get_transfer_prob returns 0.0 (with a warning) for unknown
1362+
# services, so we only need to handle cohort-not-found here.
13611363
try:
13621364
prob_transfer = transfer_model.get_transfer_prob(
13631365
source_service, admission_type
@@ -1366,18 +1368,9 @@ def compute_transfer_arrivals(
13661368
source_service, admission_type
13671369
)
13681370
except ValueError as e:
1369-
# Handle case where cohort doesn't exist in transfer model
13701371
if "not found in trained model" in str(e):
1371-
# Skip this admission type if not trained for it
13721372
continue
1373-
else:
1374-
raise ValueError(
1375-
f"Error getting transfer probabilities for '{source_service}' and admission type '{admission_type}': {e}"
1376-
)
1377-
except KeyError as e:
1378-
raise ValueError(
1379-
f"Error getting transfer probabilities for '{source_service}' and admission type '{admission_type}': {e}"
1380-
)
1373+
raise
13811374

13821375
# Skip if no transfers from this source
13831376
if prob_transfer == 0:

0 commit comments

Comments
 (0)