diff --git a/src/transport_performance/gtfs/multi_validation.py b/src/transport_performance/gtfs/multi_validation.py index 2539616b..8d6d5037 100644 --- a/src/transport_performance/gtfs/multi_validation.py +++ b/src/transport_performance/gtfs/multi_validation.py @@ -19,6 +19,7 @@ _check_parent_dir_exists, _enforce_file_extension, ) +from transport_performance.gtfs.calendar import create_calendar_from_dates class MultiGtfsInstance: @@ -111,6 +112,25 @@ def __init__(self, path: Union[str, list, pathlib.Path]) -> None: self.paths = path # instantiate the GtfsInstance's self.instances = [GtfsInstance(fpath) for fpath in path] + # ensure calendar is populated + for i, inst in enumerate(self.instances): + if inst.feed.calendar is None: + if inst.feed.calendar_dates is None: + raise FileNotFoundError( + "Both calendar and calendar_dates is empty for feed " + + self.paths[i] + ) + else: + warnings.warn( + f"No calendar found for {self.paths[i]}. Creating from" + " calendar dates" + ) + # store calendar_dates + self.instances[ + i + ].feed.calendar = create_calendar_from_dates( + calendar_dates=inst.feed.calendar_dates + ) def save_feeds(self, dir: Union[pathlib.Path, str]) -> None: """Save the GtfsInstances to a directory.