|
10 | 10 | from pandas.util.testing import assert_frame_equal
|
11 | 11 |
|
12 | 12 | from arctic.date._mktz import mktz
|
13 |
| -from tests.util import read_str_as_pandas |
| 13 | +from tests.util import read_str_as_pandas, multi_index_df_from_arrs |
14 | 14 |
|
15 | 15 | pytest_plugins = ['arctic.fixtures.arctic']
|
16 | 16 |
|
@@ -211,55 +211,69 @@ def test_bitemporal_store_read_as_of_timezone(bitemporal_library):
|
211 | 211 |
|
212 | 212 |
|
213 | 213 | def test_multi_index_ts_read_write(bitemporal_library):
|
214 |
| - ts = read_str_as_pandas(""" index 1 | index 2 | near |
215 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.0 |
216 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2.0 |
217 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2.5 |
218 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 3.0""", num_index=2) |
| 214 | + ts = multi_index_df_from_arrs( |
| 215 | + index_headers=('index 1', 'index 2'), |
| 216 | + index_arrs=[ |
| 217 | + ['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'], |
| 218 | + ['SPAM Index'] * 4 |
| 219 | + ], |
| 220 | + data_dict={'near': [1.0, 2.0, 2.5, 3.0]} |
| 221 | + ) |
219 | 222 | bitemporal_library.update('spam', ts)
|
220 | 223 | assert_frame_equal(ts, bitemporal_library.read('spam').data)
|
221 | 224 |
|
222 | 225 |
|
223 | 226 | def test_multi_index_ts_read_raw(bitemporal_library):
|
224 |
| - ts = read_str_as_pandas(""" index 1 | index 2 | near |
225 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.0 |
226 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2.0 |
227 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2.5 |
228 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 3.0""", num_index=2) |
229 |
| - |
230 |
| - expected_ts = read_str_as_pandas(""" index 1 | index 2 | observed_dt | near |
231 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 2015-01-01 | 1.0 |
232 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2015-01-01 | 2.0 |
233 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2015-01-01 | 2.5 |
234 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 2015-01-01 | 3.0""", num_index=3) |
| 227 | + ts = multi_index_df_from_arrs( |
| 228 | + index_headers=('index 1', 'index 2'), |
| 229 | + index_arrs=[ |
| 230 | + ['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'], |
| 231 | + ['SPAM Index'] * 4 |
| 232 | + ], |
| 233 | + data_dict={'near': [1.0, 2.0, 2.5, 3.0]} |
| 234 | + ) |
| 235 | + |
| 236 | + expected_ts = multi_index_df_from_arrs( |
| 237 | + index_headers=('index 1', 'index 2', 'observed_dt'), |
| 238 | + index_arrs=[ |
| 239 | + ['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'], |
| 240 | + ['SPAM Index'] * 4, |
| 241 | + ['2015-01-01'] * 4, |
| 242 | + ], |
| 243 | + data_dict={'near': [1.0, 2.0, 2.5, 3.0]} |
| 244 | + ) |
235 | 245 | bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
|
236 | 246 | assert_frame_equal(expected_ts.tz_localize(tz=LOCAL_TZ, level=2), bitemporal_library.read('spam', raw=True).data)
|
237 | 247 |
|
238 | 248 |
|
239 | 249 | def test_multi_index_update(bitemporal_library):
|
240 |
| - ts = read_str_as_pandas(""" index 1 | index 2 | near |
241 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.0 |
242 |
| - 2012-09-08 17:06:11.040 | EGG Index | 1.1 |
243 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2.0 |
244 |
| - 2012-10-08 17:06:11.040 | EGG Index | 2.1 |
245 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2.5 |
246 |
| - 2012-10-09 17:06:11.040 | EGG Index | 2.6 |
247 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 3.0 |
248 |
| - 2012-11-08 17:06:11.040 | EGG Index | 3.1""", num_index=2) |
249 |
| - ts2 = read_str_as_pandas(""" index 1 | index 2 | near |
250 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.2 |
251 |
| - 2012-09-08 17:06:11.040 | EGG Index | 1.6 |
252 |
| - 2012-12-08 17:06:11.040 | SPAM Index | 4.0""", num_index=2) |
253 |
| - expected_ts = read_str_as_pandas(""" index 1 | index 2 | near |
254 |
| - 2012-09-08 17:06:11.040 | EGG Index | 1.6 |
255 |
| - 2012-09-08 17:06:11.040 | SPAM Index | 1.2 |
256 |
| - 2012-10-08 17:06:11.040 | EGG Index | 2.1 |
257 |
| - 2012-10-08 17:06:11.040 | SPAM Index | 2.0 |
258 |
| - 2012-10-09 17:06:11.040 | EGG Index | 2.6 |
259 |
| - 2012-10-09 17:06:11.040 | SPAM Index | 2.5 |
260 |
| - 2012-11-08 17:06:11.040 | EGG Index | 3.1 |
261 |
| - 2012-11-08 17:06:11.040 | SPAM Index | 3.0 |
262 |
| - 2012-12-08 17:06:11.040 | SPAM Index | 4.0""", num_index=2) |
| 250 | + 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)) |
| 251 | + ts = multi_index_df_from_arrs( |
| 252 | + index_headers=('index 1', 'index 2'), |
| 253 | + index_arrs=[ |
| 254 | + sample_timerange, |
| 255 | + ['SPAM Index', 'EGG Index'] * 4 |
| 256 | + ], |
| 257 | + data_dict={'near': [1.0, 1.1, 2.0, 2.1, 2.5, 2.6, 3.0, 3.1]} |
| 258 | + ) |
| 259 | + |
| 260 | + ts2 = multi_index_df_from_arrs( |
| 261 | + index_headers=('index 1', 'index 2'), |
| 262 | + index_arrs=[ |
| 263 | + ['2012-09-08 17:06:11.040', '2012-09-08 17:06:11.040', '2012-12-08 17:06:11.040'], |
| 264 | + ['SPAM Index', 'EGG Index', 'SPAM Index'], |
| 265 | + ], |
| 266 | + data_dict={'near': [1.2, 1.6, 4.0]} |
| 267 | + ) |
| 268 | + |
| 269 | + expected_ts = multi_index_df_from_arrs( |
| 270 | + index_headers=('index 1', 'index 2'), |
| 271 | + index_arrs=[ |
| 272 | + sample_timerange + ['2012-12-08 17:06:11.040'], |
| 273 | + ['EGG Index', 'SPAM Index'] * 4 + ['SPAM Index'] |
| 274 | + ], |
| 275 | + data_dict={'near': [1.6, 1.2, 2.1, 2.0, 2.6, 2.5, 3.1, 3.0, 4.0]} |
| 276 | + ) |
263 | 277 | bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
|
264 | 278 | bitemporal_library.update('spam', ts2, as_of=dt(2015, 1, 2))
|
265 | 279 | assert_frame_equal(expected_ts, bitemporal_library.read('spam').data)
|
|
0 commit comments