Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle calendar.txt/calendar_dates.txt entries w/o applicable trips #27

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions tests/fixtures/trimet-vermont-2018-02-06/calendar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
unknown,0,1,1,1,1,0,0,20171120,20180309
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