|
8 | 8 | from pandas.util.testing import assert_frame_equal
|
9 | 9 |
|
10 | 10 | from arctic.multi_index import groupby_asof, fancy_group_by, insert_at
|
11 |
| -from tests.util import read_str_as_pandas |
| 11 | +from tests.util import multi_index_df_from_arrs |
12 | 12 |
|
13 | 13 |
|
14 | 14 | def get_bitemporal_test_data():
|
@@ -97,23 +97,43 @@ def test__get_ts__unsorted_index():
|
97 | 97 |
|
98 | 98 |
|
99 | 99 | def test_fancy_group_by_multi_index():
|
100 |
| - ts = read_str_as_pandas(""" index 1 | index 2 | observed_dt | near |
101 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 2015-01-01 | 1.0 |
102 |
| - 2012-09-08 17:06:11.040 | EGG Index | 2015-01-01 | 1.6 |
103 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2015-01-01 | 2.0 |
104 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2015-01-05 | 4.2 |
105 |
| - 2012-10-08 17:06:11.040 | EGG Index | 2015-01-01 | 2.1 |
106 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2015-01-01 | 2.5 |
107 |
| - 2012-10-09 17:06:11.040 | EGG Index | 2015-01-01 | 2.6 |
108 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 2015-01-01 | 3.0""", num_index=3) |
109 |
| - expected_ts = read_str_as_pandas(""" index 1 | index 2 | near |
110 |
| - 2012-09-08 17:06:11.040 | EGG Index | 1.6 |
111 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.0 |
112 |
| - 2012-10-08 17:06:11.040 | EGG Index | 2.1 |
113 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 4.2 |
114 |
| - 2012-10-09 17:06:11.040 | EGG Index | 2.6 |
115 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2.5 |
116 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 3.0""", num_index=2) |
| 100 | + |
| 101 | + ts = multi_index_df_from_arrs( |
| 102 | + index_headers=('index 1', 'index 2', 'observed_dt'), |
| 103 | + index_arrs=[ |
| 104 | + [ |
| 105 | + '2012-09-08 17:06:11.040', |
| 106 | + '2012-09-08 17:06:11.040', |
| 107 | + '2012-10-08 17:06:11.040', |
| 108 | + '2012-10-08 17:06:11.040', |
| 109 | + '2012-10-08 17:06:11.040', |
| 110 | + '2012-10-09 17:06:11.040', |
| 111 | + '2012-10-09 17:06:11.040', |
| 112 | + '2012-11-08 17:06:11.040', |
| 113 | + ], |
| 114 | + ['SPAM Index', 'EGG Index', 'SPAM Index', 'SPAM Index'] + ['EGG Index', 'SPAM Index'] * 2, |
| 115 | + ['2015-01-01'] * 3 + ['2015-01-05'] + ['2015-01-01'] * 4 |
| 116 | + ], |
| 117 | + data_dict={'near': [1.0, 1.6, 2.0, 4.2, 2.1, 2.5, 2.6, 3.0]} |
| 118 | + ) |
| 119 | + |
| 120 | + expected_ts= multi_index_df_from_arrs( |
| 121 | + index_headers=('index 1', 'index 2'), |
| 122 | + index_arrs=[ |
| 123 | + [ |
| 124 | + '2012-09-08 17:06:11.040', |
| 125 | + '2012-09-08 17:06:11.040', |
| 126 | + '2012-10-08 17:06:11.040', |
| 127 | + '2012-10-08 17:06:11.040', |
| 128 | + '2012-10-09 17:06:11.040', |
| 129 | + '2012-10-09 17:06:11.040', |
| 130 | + '2012-11-08 17:06:11.040', |
| 131 | + ], |
| 132 | + ['EGG Index', 'SPAM Index'] * 3 + ['SPAM Index'] |
| 133 | + ], |
| 134 | + data_dict={'near': [1.6, 1.0, 2.1, 4.2, 2.6, 2.5, 3.0]} |
| 135 | + ) |
| 136 | + |
117 | 137 | assert_frame_equal(expected_ts, groupby_asof(ts, dt_col=['index 1', 'index 2'], asof_col='observed_dt'))
|
118 | 138 |
|
119 | 139 |
|
|
0 commit comments