Example #1
0
def test__last_within_datetime():
    ''' Last-observed variant of the above.
    '''
    df = get_datetime_index_test_data()
    df = fancy_group_by(df, within=timedelta(hours=1), method='last')
    assert all(df['OPEN'] == [20, 180])
    assert all(df['CLOSE'] == [30, 190])
Example #2
0
def test__last_within_datetime():
    ''' Last-observed variant of the above.
    '''
    df = get_datetime_index_test_data()
    df = fancy_group_by(df, within=timedelta(hours=1), method='last')
    assert all(df['OPEN'] == [20, 180])
    assert all(df['CLOSE'] == [30, 190])
Example #3
0
def test__first_within_datetime():
    ''' This shows the groupby function can give you a timeseries of points that were observed
        within a rolling window of the sample time.
        This is like saying 'give me the timeseries as it was on the day'.
        It usually makes sense I think for the window to be the same as the sample period.
    '''
    df = get_datetime_index_test_data()
    df = fancy_group_by(df, within=timedelta(hours=1), method='first')
    assert all(df['OPEN'] == [0, 160])
    assert all(df['CLOSE'] == [10, 170])
Example #4
0
def test__first_within_datetime():
    ''' This shows the groupby function can give you a timeseries of points that were observed
        within a rolling window of the sample time.
        This is like saying 'give me the timeseries as it was on the day'.
        It usually makes sense I think for the window to be the same as the sample period.
    '''
    df = get_datetime_index_test_data()
    df = fancy_group_by(df, within=timedelta(hours=1), method='first')
    assert all(df['OPEN'] == [0, 160])
    assert all(df['CLOSE'] == [10, 170])
Example #5
0
def test_fancy_group_by_raises():
    with pytest.raises(ValueError):
        assert(fancy_group_by(None, method=None))
Example #6
0
def test__within_numeric_last():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, within=5, method='last')
    assert all(df['OPEN'] == [60, 120])
    assert all(df['CLOSE'] == [70, 130])
Example #7
0
def test__within_numeric_first():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, within=5, method='first')
    assert all(df['OPEN'] == [0, 80])
    assert all(df['CLOSE'] == [10, 90])
Example #8
0
def test__minmax_first():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, min_=3, max_=10, method='first')
    assert all(df['OPEN'] == [60, 80, 160])
    assert all(df['CLOSE'] == [70, 90, 170])
Example #9
0
def test__minmax_last():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, min_=3, max_=10, method='last')
    assert all(df['OPEN'] == [60, 140, 200])
    assert all(df['CLOSE'] == [70, 150, 210])
Example #10
0
def test__within_numeric_last():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, within=5, method='last')
    assert all(df['OPEN'] == [60, 120])
    assert all(df['CLOSE'] == [70, 130])
Example #11
0
def test__within_numeric_first():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, within=5, method='first')
    assert all(df['OPEN'] == [0, 80])
    assert all(df['CLOSE'] == [10, 90])
Example #12
0
def test__minmax_first():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, min_=3, max_=10, method='first')
    assert all(df['OPEN'] == [60, 80, 160])
    assert all(df['CLOSE'] == [70, 90, 170])
Example #13
0
def test__minmax_last():
    df = get_numeric_index_test_data()
    df = fancy_group_by(df, min_=3, max_=10, method='last')
    assert all(df['OPEN'] == [60, 140, 200])
    assert all(df['CLOSE'] == [70, 150, 210])
Example #14
0
def test_fancy_group_by_raises():
    with pytest.raises(ValueError):
        assert (fancy_group_by(None, method=None))