diff --git a/urbanaccess/gtfs/network.py b/urbanaccess/gtfs/network.py index a056b59..71e49de 100644 --- a/urbanaccess/gtfs/network.py +++ b/urbanaccess/gtfs/network.py @@ -290,8 +290,14 @@ def interpolatestoptimes(stop_times_df, calendar_selected_trips_df, day): df_for_interpolation['stop_sequence_merge'] = ( df_for_interpolation[~trailing]['stop_sequence']) + # Need to check if existing index in column names and drop if so (else + # a ValueError where Pandas can't insert b/c col already exists will occur) + drop_bool = False + if _check_if_index_name_in_cols(df_for_interpolation): + drop_bool = True + df_for_interpolation.reset_index(inplace=True, drop=drop_bool) + # Merge back into original index - df_for_interpolation.reset_index(inplace=True) interpolated_df = pd.merge(df_for_interpolation, melted, 'left', on=['stop_sequence_merge', 'unique_trip_id']) interpolated_df.set_index('index', inplace=True) @@ -763,4 +769,10 @@ def load_processed_gtfs_data(dir=config.settings.data_folder,filename=None): if 'calendar_dates' in store.keys(): gtfsfeeds_df.calendar_dates = hdf5_to_df(dir=dir,filename=filename,key='calendar_dates') - return gtfsfeeds_df \ No newline at end of file + return gtfsfeeds_df + +# helper functions +def _check_if_index_name_in_cols(df): + cols = df.columns.values + iname = df.index.name + return (iname in cols)