示例#1
0
def test_interpolator(stop_times, calendar):
    df = network._interpolate_stop_times(stop_times, calendar, day='monday')

    # unique_trip_id should be generated
    assert df.loc[1, 'unique_trip_id'] == 'a_citytrains'

    # trip 'a' should be interpolated fully
    assert df.loc[df.trip_id == 'a',
                  'departure_time_sec_interpolate'].tolist() == [
                      1, 2, 3, 4, 5
                  ]

    # trip 'b' should be skipped because it has only one null value
    # but its null value should be removed
    assert df.loc[df.trip_id == 'b',
                  'departure_time_sec_interpolate'].tolist() == [1, 2, 3, 4]

    # trip 'c' should be interpolated
    # no starting value, so first two times removed
    # NaN values should be removed from start and end
    assert df.loc[df.trip_id == 'c',
                  'departure_time_sec_interpolate'].tolist() == [3, 4]

    # trip 'd' should be removed because it's not in the calendar df
    assert len(df.loc[df.trip_id == 'd']) == 0

    # trip 'e' should interpolate the second row but leave off the trailing NA
    assert df.loc[df.trip_id == 'e',
                  'departure_time_sec_interpolate'].tolist() == [1, 2, 3, 4]
示例#2
0
def test_skip_interpolator(stop_times, calendar):
    series = pd.Series(data=[
        1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4,
        5
    ],
                       index=range(25),
                       name='departure_time_sec')

    stop_times['departure_time_sec'] = series

    df = network._interpolate_stop_times(stop_times, calendar, day='monday')

    # everything should be the same,
    # with one row dropped for calendar day filter
    assert df.departure_time_sec_interpolate.tolist() == [
        1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5
    ]