Skip to content

Commit

Permalink
Handle calendar.txt/calendar_dates.txt entries w/o applicable trips
Browse files Browse the repository at this point in the history
Ignore rows in calendar.txt and calendar_dates.txt with a service_id
that does not apply to any rows in trips.txt. This is valid GTFS.
  • Loading branch information
invisiblefunnel committed Feb 22, 2018
1 parent 41403f1 commit 2c69059
Show file tree
Hide file tree
Showing 12 changed files with 12,731 additions and 12 deletions.
18 changes: 6 additions & 12 deletions partridge/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ def _service_ids_by_date(feed):
results = defaultdict(set)
removals = defaultdict(set)

calendar = feed.calendar
caldates = feed.calendar_dates
trips = feed.trips
service_ids = set(feed.trips.service_id)

service_ids = set(trips.service_id)
# 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

# Process calendar.txt if it exists
if not calendar.empty:
calendar = calendar[calendar.service_id.isin(service_ids)].copy()

# Ensure dates have been parsed
# Parse dates
calendar.start_date = vparse_date(calendar.start_date)
calendar.end_date = vparse_date(calendar.end_date)

Expand All @@ -83,11 +80,8 @@ def _service_ids_by_date(feed):
if int(dow[date.weekday()]):
results[date].add(cal.service_id)

# Process calendar_dates.txt if it exists
if not caldates.empty:
caldates = caldates[caldates.service_id.isin(service_ids)].copy()

# Ensure dates have been parsed
# Parse dates
caldates.date = vparse_date(caldates.date)

# Split out additions and removals
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/agency.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_fare_url,agency_email,bikes_policy_url
TRIMET,TriMet,http://trimet.org/,America/Los_Angeles,en,503-238-RIDE,http://trimet.org/fares/,customerservice@trimet.org,http://trimet.org/howtoride/bikes/bikepolicies.htm
1 change: 1 addition & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/calendar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_dateunknown,0,1,1,1,1,0,0,20171120,20180309
Expand Down
115 changes: 115 additions & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/calendar_dates.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
service_id,date,exception_type
unknown,20180601,1
W.504,20180601,1
W.504,20180531,1
W.504,20180530,1
W.504,20180529,1
W.504,20180528,1
W.504,20180525,1
W.504,20180524,1
W.504,20180523,1
W.504,20180522,1
W.504,20180521,1
W.504,20180518,1
W.504,20180517,1
W.504,20180516,1
W.504,20180515,1
W.504,20180514,1
W.504,20180511,1
W.504,20180510,1
W.504,20180509,1
W.504,20180508,1
W.504,20180507,1
W.504,20180504,1
W.504,20180503,1
W.504,20180502,1
W.504,20180501,1
W.504,20180430,1
W.504,20180427,1
W.504,20180426,1
W.504,20180425,1
W.504,20180424,1
W.504,20180423,1
W.504,20180420,1
W.504,20180419,1
W.504,20180418,1
W.504,20180417,1
W.504,20180416,1
W.504,20180413,1
W.504,20180412,1
W.504,20180411,1
W.504,20180410,1
W.504,20180409,1
W.504,20180406,1
W.504,20180405,1
W.504,20180404,1
W.504,20180403,1
W.504,20180402,1
W.504,20180330,1
W.504,20180329,1
W.504,20180328,1
W.504,20180327,1
W.504,20180326,1
W.504,20180323,1
W.504,20180322,1
W.504,20180321,1
W.504,20180320,1
W.504,20180319,1
W.504,20180316,1
W.504,20180315,1
W.504,20180314,1
W.504,20180313,1
W.504,20180312,1
W.504,20180309,1
W.504,20180308,1
W.504,20180307,1
W.504,20180306,1
W.504,20180305,1
W.507,20180302,1
W.507,20180301,1
W.507,20180228,1
W.507,20180227,1
W.507,20180226,1
W.507,20180223,1
W.507,20180222,1
W.507,20180221,1
W.507,20180220,1
W.507,20180219,1
W.507,20180216,1
W.507,20180215,1
W.507,20180214,1
W.507,20180213,1
W.507,20180212,1
k.507,20180302,1
k.507,20180301,1
k.507,20180228,1
k.507,20180227,1
k.507,20180226,1
k.507,20180223,1
k.507,20180222,1
k.507,20180221,1
k.507,20180220,1
k.507,20180216,1
k.507,20180215,1
k.507,20180214,1
k.507,20180213,1
k.507,20180212,1
W.506,20180209,1
W.506,20180208,1
W.506,20180207,1
W.506,20180206,1
W.506,20180205,1
W.506,20180202,1
W.506,20180201,1
W.506,20180131,1
W.506,20180130,1
W.506,20180129,1
k.506,20180209,1
k.506,20180208,1
k.506,20180207,1
k.506,20180206,1
k.506,20180205,1
k.506,20180202,1
k.506,20180201,1
k.506,20180131,1
k.506,20180130,1
2 changes: 2 additions & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/feed_info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version,feed_id,feed_contact_url
TriMet,http://trimet.org/,en,20180128,20180602,20180128-20180206-0148,TriMet,https://groups.google.com/forum/#!forum/transit-developers-pdx
2 changes: 2 additions & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/routes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
route_id,agency_id,route_short_name,route_long_name,route_type,route_url,route_color,route_text_color,route_sort_order
1,TRIMET,1,Vermont,3,http://trimet.org//schedules/r001.htm,,,400
Loading

0 comments on commit 2c69059

Please sign in to comment.