예제 #1
0
def test_multi_index_update(bitemporal_library):
    sample_timerange = list(sorted(['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'] * 2))
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            sample_timerange,
            ['SPAM Index', 'EGG Index'] * 4
        ],
        data_dict={'near': [1.0, 1.1, 2.0, 2.1, 2.5, 2.6, 3.0, 3.1]}
    )

    ts2 = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-09-08 17:06:11.040', '2012-12-08 17:06:11.040'],
            ['SPAM Index', 'EGG Index', 'SPAM Index'],
        ],
        data_dict={'near': [1.2, 1.6, 4.0]}
    )

    expected_ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            sample_timerange + ['2012-12-08 17:06:11.040'],
            ['EGG Index', 'SPAM Index'] * 4 + ['SPAM Index']
        ],
        data_dict={'near': [1.6, 1.2, 2.1, 2.0, 2.6, 2.5, 3.1, 3.0, 4.0]}
    )
    bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
    bitemporal_library.update('spam', ts2, as_of=dt(2015, 1, 2))
    assert_frame_equal(expected_ts, bitemporal_library.read('spam').data)
    assert bitemporal_library.read('spam').last_updated == dt(2015, 1, 2, tzinfo=LOCAL_TZ)
def test_multi_index_update(bitemporal_library):
    sample_timerange = list(sorted(['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'] * 2))
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            sample_timerange,
            ['SPAM Index', 'EGG Index'] * 4
        ],
        data_dict={'near': [1.0, 1.1, 2.0, 2.1, 2.5, 2.6, 3.0, 3.1]}
    )

    ts2 = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-09-08 17:06:11.040', '2012-12-08 17:06:11.040'],
            ['SPAM Index', 'EGG Index', 'SPAM Index'],
        ],
        data_dict={'near': [1.2, 1.6, 4.0]}
    )

    expected_ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            sample_timerange + ['2012-12-08 17:06:11.040'],
            ['EGG Index', 'SPAM Index'] * 4 + ['SPAM Index']
        ],
        data_dict={'near': [1.6, 1.2, 2.1, 2.0, 2.6, 2.5, 3.1, 3.0, 4.0]}
    )
    bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
    bitemporal_library.update('spam', ts2, as_of=dt(2015, 1, 2))
    assert_frame_equal(expected_ts, bitemporal_library.read('spam').data)
    assert bitemporal_library.read('spam').last_updated == dt(2015, 1, 2, tzinfo=LOCAL_TZ)
예제 #3
0
def test_fancy_group_by_multi_index():

    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2', 'observed_dt'),
        index_arrs=[[
            '2012-09-08 17:06:11.040',
            '2012-09-08 17:06:11.040',
            '2012-10-08 17:06:11.040',
            '2012-10-08 17:06:11.040',
            '2012-10-08 17:06:11.040',
            '2012-10-09 17:06:11.040',
            '2012-10-09 17:06:11.040',
            '2012-11-08 17:06:11.040',
        ], ['SPAM Index', 'EGG Index', 'SPAM Index', 'SPAM Index'] +
                    ['EGG Index', 'SPAM Index'] * 2,
                    ['2015-01-01'] * 3 + ['2015-01-05'] + ['2015-01-01'] * 4],
        data_dict={'near': [1.0, 1.6, 2.0, 4.2, 2.1, 2.5, 2.6, 3.0]})

    expected_ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[[
            '2012-09-08 17:06:11.040',
            '2012-09-08 17:06:11.040',
            '2012-10-08 17:06:11.040',
            '2012-10-08 17:06:11.040',
            '2012-10-09 17:06:11.040',
            '2012-10-09 17:06:11.040',
            '2012-11-08 17:06:11.040',
        ], ['EGG Index', 'SPAM Index'] * 3 + ['SPAM Index']],
        data_dict={'near': [1.6, 1.0, 2.1, 4.2, 2.6, 2.5, 3.0]})

    assert_frame_equal(
        expected_ts,
        groupby_asof(ts, dt_col=['index 1', 'index 2'],
                     asof_col='observed_dt'))
def test_multi_index_ts_read_write(bitemporal_library):
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )
    bitemporal_library.update('spam', ts)
    assert_frame_equal(ts, bitemporal_library.read('spam').data)
예제 #5
0
def test_multi_index_ts_read_write(bitemporal_library):
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )
    bitemporal_library.update('spam', ts)
    assert_frame_equal(ts, bitemporal_library.read('spam').data)
def test_multi_index_ts_read_raw(bitemporal_library):
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )

    expected_ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2', 'observed_dt'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4,
            ['2015-01-01'] * 4,
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )
    bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
    assert_frame_equal(expected_ts.tz_localize(tz=LOCAL_TZ, level=2), bitemporal_library.read('spam', raw=True).data)
예제 #7
0
def test_multi_index_ts_read_raw(bitemporal_library):
    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )

    expected_ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2', 'observed_dt'),
        index_arrs=[
            ['2012-09-08 17:06:11.040', '2012-10-08 17:06:11.040', '2012-10-09 17:06:11.040', '2012-11-08 17:06:11.040'],
            ['SPAM Index'] * 4,
            ['2015-01-01'] * 4,
        ],
        data_dict={'near': [1.0, 2.0, 2.5, 3.0]}
    )
    bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
    assert_frame_equal(expected_ts.tz_localize(tz=LOCAL_TZ, level=2), bitemporal_library.read('spam', raw=True).data)
예제 #8
0
def test_fancy_group_by_multi_index():

    ts = multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2', 'observed_dt'),
        index_arrs=[
            [
                '2012-09-08 17:06:11.040',
                '2012-09-08 17:06:11.040',
                '2012-10-08 17:06:11.040',
                '2012-10-08 17:06:11.040',
                '2012-10-08 17:06:11.040',
                '2012-10-09 17:06:11.040',
                '2012-10-09 17:06:11.040',
                '2012-11-08 17:06:11.040',
            ],
            ['SPAM Index', 'EGG Index', 'SPAM Index', 'SPAM Index'] + ['EGG Index', 'SPAM Index'] * 2,
            ['2015-01-01'] * 3 + ['2015-01-05'] + ['2015-01-01'] * 4
        ],
        data_dict={'near': [1.0, 1.6, 2.0, 4.2, 2.1, 2.5, 2.6, 3.0]}
    )

    expected_ts= multi_index_df_from_arrs(
        index_headers=('index 1', 'index 2'),
        index_arrs=[
            [
                '2012-09-08 17:06:11.040',
                '2012-09-08 17:06:11.040',
                '2012-10-08 17:06:11.040',
                '2012-10-08 17:06:11.040',
                '2012-10-09 17:06:11.040',
                '2012-10-09 17:06:11.040',
                '2012-11-08 17:06:11.040',
            ],
            ['EGG Index', 'SPAM Index'] * 3 + ['SPAM Index']
        ],
        data_dict={'near': [1.6, 1.0, 2.1, 4.2, 2.6, 2.5, 3.0]}
    )

    assert_frame_equal(expected_ts, groupby_asof(ts, dt_col=['index 1', 'index 2'], asof_col='observed_dt'))