Bondify / gtfs_functions

Package with useful functions to create geo-spatial visualizations from a GTFS.
MIT License
114 stars 30 forks source link

unable to parse schedule in feed with calendar.txt omitted #40

Closed anthonymobile closed 7 months ago

anthonymobile commented 8 months ago

I am trying to use gtfs_functions with the NJTransit feeds, which omit calendar.txt

This is permitted in the GTFS spec, but throws a ton of mistting start_date errors in gtfs_functions

time_windows = [0, 6, 9, 15.5, 19, 22, 24]

feed = Feed(gtfs_path, time_windows=time_windows)
stop_freq = feed.stops_freq

results in (regardless of start_date or end_date specified on the feed)

INFO:root:Reading "stop_times.txt".
INFO:root:get trips in stop_times
INFO:root:accessing trips
INFO:root:Reading "routes.txt".
INFO:root:Start date is None. You should either specify a start date or set busiest_date to True.
INFO:root:Reading "trips.txt".
INFO:root:File "calendar.txt" not found.
INFO:root:Reading "calendar_dates.txt".

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 4
      1 time_windows = [0, 6, 9, 15.5, 19, 22, 24]
      3 feed = Feed(gtfs_path, time_windows=time_windows)
----> 4 stop_freq = feed.stops_freq

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:217, in Feed.stops_freq(self)
    214 @property
    215 def stops_freq(self):
    216     if self._stops_freq is None:
--> 217         self._stops_freq = self.get_stops_freq()
    219     return self._stops_freq

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:717, in Feed.get_stops_freq(self)
    711 def get_stops_freq(self):
    712     """
    713     Get the stop frequencies. For each stop of each route it 
    714     returns the bus frequency in minutes/bus broken down by
    715     time window.
    716     """
--> 717     stop_times = self.stop_times
    718     stops = self.stops
    719     cutoffs = self.time_windows

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:203, in Feed.stop_times(self)
    200 @property
    201 def stop_times(self):
    202     if self._stop_times is None:
--> 203         self._stop_times = self.get_stop_times()
    205     return self._stop_times

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:647, in Feed.get_stop_times(self)
    645 else:
    646     logging.info('get trips in stop_times')
--> 647     trips = self.trips
    648 stops = self.stops
    650 # Fix data types

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:173, in Feed.trips(self)
    171 logging.info('accessing trips')
    172 if self._trips is None:
--> 173     self._trips = self.get_trips()
    175 if self._patterns and self._trips_patterns is None:
    176     (trips_patterns, routes_patterns) = self.get_routes_patterns(
    177             self._trips)

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:560, in Feed.get_trips(self)
    549 if (self.busiest_date) | (dates!=[]):
    550     """
    551     In the case we have three possibilites:
    552     1. busiest_date=True & dates==[]: in this case the user looks for the 
   (...)
    558         the "dates" variable at all.
    559     """
--> 560     dates_service_id = self.parse_calendar()
    562     # If busiest_date=True, we have to count the number of trips
    563     if self.busiest_date:
    564         # Trip per date

File /opt/bin/mambaforge/envs/njtransit/lib/python3.10/site-packages/gtfs_functions/gtfs_functions.py:452, in Feed.parse_calendar(self)
    449 busiest_date = self.busiest_date
    451 # Parse dates
--> 452 calendar['start_date_dt'] = calendar.start_date.astype(str).apply(pl.parse)
    453 calendar['end_date_dt'] = calendar.end_date.astype(str).apply(pl.parse) 
    455 # Get all dates for a given service_id

AttributeError: 'NoneType' object has no attribute 'start_date'
Bondify commented 7 months ago

thanks for pointing this out @anthonymobile . Can you point me to the gtfs file you're using so I can use for testing?

anthonymobile commented 7 months ago

NJTransit Buses feed

https://github.com/anthonymobile/njt-bus-fare-equity/blob/main/data/bus_data.zip

Bondify commented 7 months ago

@anthonymobile thanks! version 2.4 of the package should solve this. Please let me know how it goes.

anthonymobile commented 7 months ago

sorry i must have an old version pinned due to dependencies

anthonymobile commented 7 months ago

closed