Example #1
0
def test_start_stop_dates_all_false():
    """If the passed to start_stop_dates is empty the returns (None, None)."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(False, index=index)
    assert (None, None) == gaps.start_stop_dates(series)
Example #2
0
def test_start_stop_dates_not_enough_days():
    """Fewer than 10 days of True gives not start/stop dates."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(False, index=index)
    series['02-23-2020':'02-24-2020'] = True
    assert (None, None) == gaps.start_stop_dates(series)
Example #3
0
def test_start_stop_dates_first_day_false():
    """If day one is all False, then start date should be day 2."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(True, index=index)
    series.loc['01-01-2020'] = False
    firstvalid, lastvalid = gaps.start_stop_dates(series)
    assert firstvalid.date() == pd.Timestamp('01-02-2020').date()
    assert lastvalid.date() == pd.Timestamp('08-01-2020').date()
Example #4
0
def test_start_stop_dates_all_true():
    """If all values are True then start and stop are equal to first and
    last day of the series."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(True, index=index)
    firstvalid, lastvalid = gaps.start_stop_dates(series)
    assert firstvalid.date() == series.index[0].date()
    assert lastvalid.date() == series.index[-1].date()
Example #5
0
def test_start_stop_dates_first_and_fifth_days_missing():
    """First valid date should be the sixth of January."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(True, index=index)
    series.loc['01-01-2020'] = False
    series.loc['01-05-2020'] = False
    firstvalid, lastvalid = gaps.start_stop_dates(series)
    assert firstvalid.date() == pd.Timestamp('01-06-2020').date()
    assert lastvalid.date() == pd.Timestamp('08-01-2020').date()
Example #6
0
def test_start_stop_dates_with_gaps_in_middle():
    """large gaps between the first and last sufficiently long block of
    consecutive 'good' days have no effect on the start and stop
    date."""
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(True, index=index)
    series['03-05-2020':'03-25-2020'] = False
    start, end = gaps.start_stop_dates(series, days=5)
    assert start.date() == index[0].date()
    assert end.date() == index[-1].date()
Example #7
0
def test_start_stop_dates_one_day():
    """Works when there is exactly the minimum number of consecutive
    days with data.

    """
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(False, index=index)
    series['05-05-2020'] = True
    start, end = gaps.start_stop_dates(series, days=1)
    assert start.date() == pd.Timestamp('05-05-2020').date()
    assert end.date() == pd.Timestamp('05-05-2020').date()
Example #8
0
def test_start_stop_dates_last_two_days_missing():
    """If the last two days of data are missing last valid day should be
    July 30.

    """
    index = pd.date_range(freq='15T',
                          start='01-01-2020',
                          end='08-01-2020 23:00')
    series = pd.Series(True, index=index)
    series.loc['07-31-2020':'08-01-2020'] = False
    firstvalid, lastvalid = gaps.start_stop_dates(series)
    assert firstvalid.date() == pd.Timestamp('01-01-2020').date()
    assert lastvalid.date() == pd.Timestamp('07-30-2020').date()