Bondify / gtfs_functions

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

Feed.segments fails, "Index(...) must be called with a collection of some kind, 'cut_flag' was passed" #29

Closed vejendla closed 7 months ago

vejendla commented 9 months ago

I'm attempting to create a frequency map for Pittsburgh Regional Transit (see GTFS feed here: https://www.rideprt.org/business-center/developer-resources/developer-license-agreement/). I am following this tutorial.

I am using Python 3 in JupyterLab via an Anaconda Notebook. Here is my code:

from gtfs_functions import Feed from gtfs_functions import Feed feed = Feed("PRT.zip", time_windows=[0, 6, 9, 15, 19, 22, 24], busiest_date = False) segments_gdf = feed.segments

The last line is where the error appears. After running for a few seconds, the following box appears:

INFO:root:Reading "stop_times.txt".
INFO:root:get trips in stop_times
INFO:root:accessing trips
INFO:root:Reading "routes.txt".
INFO:root:Reading "trips.txt".
INFO:numexpr.utils:NumExpr defaulting to 8 threads.
INFO:root:Reading "stop_times.txt".
INFO:root:_trips is defined in stop_times
INFO:root:Reading "stops.txt".
INFO:root:computing patterns
INFO:root:Reading "shapes.txt".
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-319c94383414> in <module>
----> 1 segments_gdf = feed.segments

~/opt/anaconda3/lib/python3.8/site-packages/gtfs_functions/gtfs_functions.py in segments(self)
    208     def segments(self):
    209         if self._segments is None:
--> 210             self._segments = self.get_segments()
    211 
    212         return self._segments

~/opt/anaconda3/lib/python3.8/site-packages/gtfs_functions/gtfs_functions.py in get_segments(self)
    794 
    795         # drop all non stops (had to combine first fto get their gdf index)
--> 796         cuts = gdf.where(gdf.cut_flag).dropna(subset="cut_flag")
    797         cuts = cuts.astype({"shape_id": str, "stop_sequence": int, "direction_id": int})
    798         cuts[["end_stop_id", "end_stop_name"]] = cuts.groupby("shape_id")[['stop_id', "stop_name"]].shift(-1)

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py in dropna(self, axis, how, thresh, subset, inplace)
   5157         if subset is not None:
   5158             ax = self._get_axis(agg_axis)
-> 5159             indices = ax.get_indexer_for(subset)
   5160             check = indices == -1
   5161             if check.any():

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_indexer_for(self, target, **kwargs)
   4958         """
   4959         if self._index_as_unique:
-> 4960             return self.get_indexer(target, **kwargs)
   4961         indexer, _ = self.get_indexer_non_unique(target)
   4962         return indexer

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_indexer(self, target, method, limit, tolerance)
   3145     ) -> np.ndarray:
   3146         method = missing.clean_reindex_fill_method(method)
-> 3147         target = ensure_index(target)
   3148         if tolerance is not None:
   3149             tolerance = self._convert_tolerance(tolerance, target)

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in ensure_index(index_like, copy)
   5915             index_like = copy_func(index_like)
   5916 
-> 5917     return Index(index_like)
   5918 
   5919 

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in __new__(cls, data, dtype, copy, name, tupleize_cols, **kwargs)
    370 
    371         elif data is None or is_scalar(data):
--> 372             raise cls._scalar_data_error(data)
    373         elif hasattr(data, "__array__"):
    374             return Index(np.asarray(data), dtype=dtype, copy=copy, name=name, **kwargs)

TypeError: Index(...) must be called with a collection of some kind, 'cut_flag' was passed

What is the source of this error? How can I get around it?

Bondify commented 9 months ago

hi @vejendla can you give it another try with the newest version of the package? This should be fixed