Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 5
0
def test_fancy_group_by_raises():
    with pytest.raises(ValueError):
        assert(fancy_group_by(None, method=None))
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 14
0
def test_fancy_group_by_raises():
    with pytest.raises(ValueError):
        assert (fancy_group_by(None, method=None))