diff --git a/pipelines/collate_plots.py b/pipelines/collate_plots.py index 3f396d87..deda97d7 100644 --- a/pipelines/collate_plots.py +++ b/pipelines/collate_plots.py @@ -5,8 +5,9 @@ import os from pathlib import Path +from forecasttools import ensure_listlike from pypdf import PdfWriter -from utils import ensure_listlike, get_all_forecast_dirs +from utils import get_all_forecast_dirs def merge_pdfs_and_save( diff --git a/pipelines/utils.py b/pipelines/utils.py index c18215cc..9504cd86 100644 --- a/pipelines/utils.py +++ b/pipelines/utils.py @@ -6,39 +6,11 @@ import datetime import os import re -from collections.abc import MutableSequence from pathlib import Path disease_map_lower_ = {"influenza": "Influenza", "covid-19": "COVID-19"} -def ensure_listlike(x): - """ - Ensure that an object either behaves like a - :class:`MutableSequence` and if not return a - one-item :class:`list` containing the object. - - Useful for handling list-of-strings inputs - alongside single strings. - - Based on this _`StackOverflow approach - `. - - Parameters - ---------- - x - The item to ensure is :class:`list`-like. - - Returns - ------- - MutableSequence - ``x`` if ``x`` is a :class:`MutableSequence` - otherwise ``[x]`` (i.e. a one-item list containing - ``x``. - """ - return x if isinstance(x, MutableSequence) else [x] - - def parse_model_batch_dir_name(model_batch_dir_name): """ Parse the name of a model batch directory,