From e55cafbd45b1c3405cdfc3866f65800f93d00601 Mon Sep 17 00:00:00 2001 From: Danny Whalen Date: Sat, 24 Feb 2018 09:00:17 -0800 Subject: [PATCH] Handle feeds with only one of calendar.txt and calendar_dates.txt This bug was introduced in #27 and released in v0.6.0. --- partridge/readers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/partridge/readers.py b/partridge/readers.py index 52732b3..6bccf5d 100644 --- a/partridge/readers.py +++ b/partridge/readers.py @@ -59,10 +59,16 @@ def _service_ids_by_date(feed): removals = defaultdict(set) service_ids = set(feed.trips.service_id) + calendar = feed.calendar + caldates = feed.calendar_dates - # Only consider calendar.txt/calendar_dates.txt rows with applicable trips - calendar = feed.calendar[feed.calendar.service_id.isin(service_ids)].copy() - caldates = feed.calendar_dates[feed.calendar_dates.service_id.isin(service_ids)].copy() # noqa E501 + if not calendar.empty: + # Only consider calendar.txt rows with applicable trips + calendar = calendar[calendar.service_id.isin(service_ids)].copy() + + if not caldates.empty: + # Only consider calendar_dates.txt rows with applicable trips + caldates = caldates[caldates.service_id.isin(service_ids)].copy() if not calendar.empty: # Parse dates