Skip to content

Commit

Permalink
Handle feeds with only one of calendar.txt and calendar_dates.txt
Browse files Browse the repository at this point in the history
This bug was introduced in #27 and released in v0.6.0.
  • Loading branch information
invisiblefunnel committed Feb 24, 2018
1 parent df45b38 commit c405069
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 3 deletions.
12 changes: 9 additions & 3 deletions partridge/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
4,אגד תעבורה,http://www.egged-taavura.co.il,Asia/Jerusalem,he,,
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
service_id,sunday,monday,tuesday,wednesday,thursday,friday,saturday,start_date,end_date
56449751,0,0,0,0,1,0,0,20180301,20180301
56449760,1,1,1,1,1,0,0,20180223,20180227
56449767,0,0,0,1,0,0,0,20180228,20180228
56449780,1,1,1,1,1,0,0,20180304,20180424
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_desc,route_type,route_color
2126,4,6א,הרימון/השיקמה-נתניה<->תחנה מרכזית נתניה/הורדה-נתניה-2ה,21006-2-ה,3,
151 changes: 151 additions & 0 deletions tests/fixtures/israel-public-transportation-route-2126/shapes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence
93890,32.327459,34.858705,143
93890,32.327423,34.858596,144
93890,32.327338,34.858504,145
93890,32.327223,34.858463,146
93890,32.327152,34.858446,147
93890,32.327074,34.858438,148
93890,32.327010,34.858480,149
93890,32.326985,34.858567,150
93890,32.351540,34.865603,1
93890,32.352333,34.865661,2
93890,32.352337,34.865450,3
93890,32.352338,34.864894,4
93890,32.352380,34.864290,5
93890,32.352395,34.864103,6
93890,32.352419,34.863863,7
93890,32.352451,34.863608,8
93890,32.352447,34.863522,9
93890,32.352404,34.863475,10
93890,32.352211,34.863387,11
93890,32.351986,34.863292,12
93890,32.351765,34.863241,13
93890,32.351994,34.861974,14
93890,32.352009,34.861907,15
93890,32.352232,34.860699,16
93890,32.352341,34.859920,17
93890,32.352327,34.859644,18
93890,32.352297,34.859306,19
93890,32.352241,34.859033,20
93890,32.352178,34.858822,21
93890,32.352063,34.858432,22
93890,32.352013,34.858252,23
93890,32.351972,34.858095,24
93890,32.351900,34.858125,25
93890,32.351838,34.858128,26
93890,32.351869,34.858305,27
93890,32.351937,34.858538,28
93890,32.352096,34.858993,29
93890,32.352297,34.859306,30
93890,32.352327,34.859644,31
93890,32.352341,34.859920,32
93890,32.352232,34.860699,33
93890,32.352009,34.861907,34
93890,32.351994,34.861974,35
93890,32.351104,34.861691,36
93890,32.349989,34.861481,37
93890,32.349653,34.861418,38
93890,32.349296,34.861351,39
93890,32.349143,34.861329,40
93890,32.348307,34.861181,41
93890,32.347840,34.861107,42
93890,32.347604,34.861060,43
93890,32.347792,34.860210,44
93890,32.347857,34.859900,45
93890,32.348111,34.858730,46
93890,32.348250,34.858127,47
93890,32.348289,34.857865,48
93890,32.348319,34.857640,49
93890,32.348322,34.857502,50
93890,32.347484,34.857434,51
93890,32.346667,34.857347,52
93890,32.346537,34.857322,53
93890,32.346444,34.857312,54
93890,32.346373,34.857309,55
93890,32.346324,34.857321,56
93890,32.346324,34.857286,57
93890,32.346315,34.857256,58
93890,32.346296,34.857223,59
93890,32.346269,34.857198,60
93890,32.346243,34.857185,61
93890,32.346229,34.857183,62
93890,32.346209,34.857180,63
93890,32.346174,34.857188,64
93890,32.346144,34.857207,65
93890,32.346120,34.857236,66
93890,32.346103,34.857279,67
93890,32.346102,34.857287,68
93890,32.346100,34.857319,69
93890,32.346108,34.857358,70
93890,32.346131,34.857397,71
93890,32.346165,34.857425,72
93890,32.346195,34.857434,73
93890,32.346228,34.857524,74
93890,32.346258,34.857644,75
93890,32.346285,34.857936,76
93890,32.346278,34.858281,77
93890,32.346193,34.859343,78
93890,32.346157,34.859705,79
93890,32.346097,34.860128,80
93890,32.346062,34.860262,81
93890,32.346007,34.860443,82
93890,32.345931,34.860599,83
93890,32.345796,34.860821,84
93890,32.345554,34.861167,85
93890,32.345230,34.861707,86
93890,32.345182,34.861863,87
93890,32.345137,34.862091,88
93890,32.345088,34.862431,89
93890,32.344711,34.862392,90
93890,32.344474,34.862366,91
93890,32.344184,34.862327,92
93890,32.343854,34.862274,93
93890,32.343527,34.862229,94
93890,32.343307,34.862192,95
93890,32.342727,34.862104,96
93890,32.341935,34.861973,97
93890,32.342107,34.860369,98
93890,32.342115,34.860245,99
93890,32.342018,34.860233,100
93890,32.341832,34.860211,101
93890,32.341423,34.860162,102
93890,32.340576,34.860012,103
93890,32.338986,34.859769,104
93890,32.338758,34.859735,105
93890,32.338155,34.859656,106
93890,32.337927,34.859625,107
93890,32.337561,34.859582,108
93890,32.337285,34.859553,109
93890,32.336833,34.859505,110
93890,32.336127,34.859432,111
93890,32.335126,34.859322,112
93890,32.335036,34.859312,113
93890,32.334515,34.859242,114
93890,32.333625,34.859148,115
93890,32.333020,34.859069,116
93890,32.332907,34.859055,117
93890,32.332387,34.859011,118
93890,32.331902,34.858962,119
93890,32.331735,34.858945,120
93890,32.331640,34.858936,121
93890,32.331083,34.858888,122
93890,32.330878,34.858871,123
93890,32.330518,34.858832,124
93890,32.330411,34.858821,125
93890,32.330072,34.858784,126
93890,32.330005,34.858777,127
93890,32.329537,34.858730,128
93890,32.329452,34.858708,129
93890,32.329399,34.858693,130
93890,32.329171,34.858632,131
93890,32.329154,34.858625,132
93890,32.328799,34.858496,133
93890,32.328502,34.858372,134
93890,32.328246,34.858264,135
93890,32.328216,34.858252,136
93890,32.328169,34.858299,137
93890,32.328147,34.858366,138
93890,32.327893,34.859095,139
93890,32.327552,34.858947,140
93890,32.327530,34.858921,141
93890,32.327495,34.858881,142
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type,shape_dist_traveled
435227_230218,05:10:00,05:10:00,606,1,0,1,0
435227_230218,05:10:56,05:10:56,639,2,0,0,164
435227_230218,05:11:41,05:11:41,396,3,0,0,351
435227_230218,05:13:20,05:13:20,25438,4,0,0,764
435227_230218,05:16:03,05:16:03,389,5,0,0,1444
435227_230218,05:16:51,05:16:51,387,6,0,0,1642
435227_230218,05:17:46,05:17:46,382,7,0,0,2069
435227_230218,05:19:00,05:19:00,381,8,0,0,2338
435227_230218,05:20:18,05:20:18,385,9,0,0,2663
435227_230218,05:21:10,05:21:10,724,10,0,0,2880
435227_230218,05:22:44,05:22:44,374,11,0,0,3262
435227_230218,05:23:18,05:23:18,372,12,0,0,3420
435227_230218,05:23:40,05:23:40,371,13,0,0,3586
435227_230218,05:24:28,05:24:28,368,14,0,0,3828
435227_230218,05:25:21,05:25:21,366,15,0,0,4164
435227_230218,05:26:36,05:26:36,356,16,0,0,4554
435227_230218,05:27:25,05:27:25,354,17,0,0,4802
435227_230218,05:28:54,05:28:54,599,18,1,0,5089
435227_040318,05:10:00,05:10:00,606,1,0,1,0
435227_040318,05:10:56,05:10:56,639,2,0,0,164
435227_040318,05:11:41,05:11:41,396,3,0,0,351
435227_040318,05:13:20,05:13:20,25438,4,0,0,764
435227_040318,05:16:03,05:16:03,389,5,0,0,1444
435227_040318,05:16:51,05:16:51,387,6,0,0,1642
435227_040318,05:17:46,05:17:46,382,7,0,0,2069
435227_040318,05:19:00,05:19:00,381,8,0,0,2338
435227_040318,05:20:18,05:20:18,385,9,0,0,2663
435227_040318,05:21:10,05:21:10,724,10,0,0,2880
435227_040318,05:22:44,05:22:44,374,11,0,0,3262
435227_040318,05:23:18,05:23:18,372,12,0,0,3420
435227_040318,05:23:40,05:23:40,371,13,0,0,3586
435227_040318,05:24:28,05:24:28,368,14,0,0,3828
435227_040318,05:25:21,05:25:21,366,15,0,0,4164
435227_040318,05:26:36,05:26:36,356,16,0,0,4554
435227_040318,05:27:25,05:27:25,354,17,0,0,4802
435227_040318,05:28:54,05:28:54,599,18,1,0,5089
4679602_280218,05:10:00,05:10:00,606,1,0,1,0
4679602_280218,05:10:56,05:10:56,639,2,0,0,164
4679602_280218,05:11:41,05:11:41,396,3,0,0,351
4679602_280218,05:13:20,05:13:20,25438,4,0,0,764
4679602_280218,05:16:03,05:16:03,389,5,0,0,1444
4679602_280218,05:16:51,05:16:51,387,6,0,0,1642
4679602_280218,05:17:46,05:17:46,382,7,0,0,2069
4679602_280218,05:19:00,05:19:00,381,8,0,0,2338
4679602_280218,05:20:18,05:20:18,385,9,0,0,2663
4679602_280218,05:21:10,05:21:10,724,10,0,0,2880
4679602_280218,05:22:44,05:22:44,374,11,0,0,3262
4679602_280218,05:23:18,05:23:18,372,12,0,0,3420
4679602_280218,05:23:40,05:23:40,371,13,0,0,3586
4679602_280218,05:24:28,05:24:28,368,14,0,0,3828
4679602_280218,05:25:21,05:25:21,366,15,0,0,4164
4679602_280218,05:26:36,05:26:36,356,16,0,0,4554
4679602_280218,05:27:25,05:27:25,354,17,0,0,4802
4679602_280218,05:28:54,05:28:54,599,18,1,0,5089
3528905_010318,05:10:00,05:10:00,606,1,0,1,0
3528905_010318,05:10:56,05:10:56,639,2,0,0,164
3528905_010318,05:11:41,05:11:41,396,3,0,0,351
3528905_010318,05:13:20,05:13:20,25438,4,0,0,764
3528905_010318,05:16:03,05:16:03,389,5,0,0,1444
3528905_010318,05:16:51,05:16:51,387,6,0,0,1642
3528905_010318,05:17:46,05:17:46,382,7,0,0,2069
3528905_010318,05:19:00,05:19:00,381,8,0,0,2338
3528905_010318,05:20:18,05:20:18,385,9,0,0,2663
3528905_010318,05:21:10,05:21:10,724,10,0,0,2880
3528905_010318,05:22:44,05:22:44,374,11,0,0,3262
3528905_010318,05:23:18,05:23:18,372,12,0,0,3420
3528905_010318,05:23:40,05:23:40,371,13,0,0,3586
3528905_010318,05:24:28,05:24:28,368,14,0,0,3828
3528905_010318,05:25:21,05:25:21,366,15,0,0,4164
3528905_010318,05:26:36,05:26:36,356,16,0,0,4554
3528905_010318,05:27:25,05:27:25,354,17,0,0,4802
3528905_010318,05:28:54,05:28:54,599,18,1,0,5089
19 changes: 19 additions & 0 deletions tests/fixtures/israel-public-transportation-route-2126/stops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,location_type,parent_station,zone_id
354,39269,ויצמן/הרצל,רחוב:שדרות חיים וייצמן 5 עיר: נתניה רציף: קומה:,32.328953,34.858496,0,,7400
356,39271,ויצמן/ששת הימים,רחוב:שדרות חיים וייצמן עיר: נתניה רציף: קומה:,32.331154,34.858841,0,,7400
366,39281,י.ח. ברנר/שד. חיים וייצמן,רחוב:שדרות חיים וייצמן 53 עיר: נתניה רציף: קומה:,32.334658,34.859208,0,,7400
368,39283,שדרות וייצמן/יהודה הנשיא,רחוב:שדרות חיים וייצמן עיר: נתניה רציף: קומה:,32.337669,34.859541,0,,7400
371,39286,וייצמן/איכילוב,רחוב:שדרות חיים וייצמן 95 עיר: נתניה רציף: קומה:,32.339836,34.859845,0,,7400
372,39287,הרב הרצוג/שדרות חיים וייצמן,רחוב:שדרות חיים וייצמן 109 עיר: נתניה רציף: קומה:,32.341324,34.860090,0,,7400
374,39289,בית הבאר/נחום סוקולוב,רחוב:נחום סוקולוב 19 עיר: נתניה רציף: קומה:,32.342087,34.860981,0,,7400
381,39296,בית חולים לניאדו,רחוב:הרב מיימון 4 עיר: נתניה רציף: קומה:,32.346220,34.857721,0,,7400
382,39297,הגדוד העברי/דברי חיים,רחוב:דברי חיים 47 עיר: נתניה רציף: קומה:,32.347980,34.857421,0,,7400
385,39300,הרב מיימון/מוריה,רחוב:הרב מיימון 30 עיר: נתניה רציף: קומה:,32.345629,34.860975,0,,7400
387,39302,הגפן\הגדוד העבר,רחוב:הגפן 3 עיר: נתניה רציף: קומה:,32.348002,34.861079,0,,7400
389,39304,הגפן/שד. עין התכלת,רחוב:הגפן 19 עיר: נתניה רציף: קומה:,32.349772,34.861387,0,,7400
396,39311,הגפן/השקד,רחוב:השקד 38 עיר: נתניה רציף: קומה:,32.351904,34.862728,0,,7400
599,39522,תחנה מרכזית נתניה/הורדה,רחוב:פינסקר עיר: נתניה רציף: קומה:,32.327128,34.858390,0,,7400
606,39529,הרימון/השיקמה,רחוב:השיקמה 8 עיר: נתניה רציף: קומה:,32.352174,34.865703,0,,7400
639,39566,הרימון/התמר,רחוב:הרימון 27 עיר: נתניה רציף: קומה:,32.352440,34.864109,0,,7400
724,39657,בלפור/קמיל הויסמנס,רחוב:קמיל הויסמנס 29 עיר: נתניה רציף: קומה:,32.344502,34.862316,0,,7400
25438,38544,בית גיל הזהב/השקד,רחוב:השקד 50 עיר: נתניה רציף: קומה:,32.352105,34.858411,0,,7400
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
route_id,service_id,trip_id,trip_headsign,direction_id,shape_id
2126,56449760,435227_230218,תחנה מרכזית,1,93890
2126,56449780,435227_040318,תחנה מרכזית,1,93890
2126,56449751,3528905_010318,תחנה מרכזית,1,93890
2126,56449767,4679602_280218,תחנה מרכזית,1,93890
5 changes: 5 additions & 0 deletions tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def test_unused_service_ids():
ptg.read_service_ids_by_date(path)


def test_missing_calendar_dates():
path = fixture('israel-public-transportation-route-2126')
ptg.read_service_ids_by_date(path)


@pytest.mark.parametrize('path', [
zip_file('amazon-2017-08-06'),
fixture('amazon-2017-08-06'),
Expand Down

0 comments on commit c405069

Please sign in to comment.