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