Ejemplo n.º 1
0
def test_read_ts_with_historical_update_and_new_row(bitemporal_library):
    with patch('arctic.store.bitemporal_store.dt') as mock_dt:
        mock_dt.now.return_value = dt(2015, 5, 1)
        mock_dt.side_effect = lambda *args, **kwargs: dt(*args, **kwargs)
        bitemporal_library.update('spam', ts1)

    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-10-09 17:06:11.040 | 4.2
                                                         2012-12-01 17:06:11.040 | 100"""
                                                 ),
                              as_of=dt(2015, 5, 2))

    assert_frame_equal(
        bitemporal_library.read('spam').data,
        read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  4.2
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""
                           ))

    assert_frame_equal(
        bitemporal_library.read('spam', as_of=dt(2015, 5, 1, 10)).data, ts1)
def test_read_ts_with_historical_update(bitemporal_library):
    with patch('arctic.store.bitemporal_store.dt') as mock_dt:
        mock_dt.now.return_value = dt(2015, 5, 1)
        mock_dt.side_effect = lambda *args, **kwargs: dt(*args, **kwargs)
        bitemporal_library.update('spam', ts1)

    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 | 4.2"""),
                              as_of=dt(2015, 5, 2))

    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 | 6.6"""),
                              as_of=dt(2015, 5, 3))
    assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 2, 10, tzinfo=pytz.timezone("Europe/London"))).data, read_str_as_pandas(
                                                                                    """sample_dt   | near
                                                                           2012-09-08 17:06:11.040 |  1.0
                                                                           2012-10-08 17:06:11.040 |  2.0
                                                                           2012-10-09 17:06:11.040 |  4.2
                                                                           2012-11-08 17:06:11.040 |  3.0"""))

    assert_frame_equal(bitemporal_library.read('spam').data, read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  6.6
                                                                       2012-11-08 17:06:11.040 |  3.0"""))

    assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 1, 10, tzinfo=pytz.timezone("Europe/London"))).data, ts1)
Ejemplo n.º 3
0
def test_insert_versions_inbetween_works_ok(bitemporal_library):
    bitemporal_library.update('spam', ts1, as_of=dt(2015, 5, 1))
    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 100"""
                                                 ),
                              as_of=dt(2015, 5, 10))

    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""
                                                 ),
                              as_of=dt(2015, 5, 8))

    assert_frame_equal(
        bitemporal_library.read('spam').data,
        read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  2.5
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""
                           ))

    assert_frame_equal(
        bitemporal_library.read('spam', as_of=dt(2015, 5, 9)).data,
        read_str_as_pandas("""  sample_dt | near
                                                                     2012-09-08 17:06:11.040 |  1.0
                                                                     2012-10-08 17:06:11.040 |  2.0
                                                                     2012-10-09 17:06:11.040 |  2.5
                                                                     2012-11-08 17:06:11.040 |  3.0
                                                                     2012-12-01 17:06:11.040 |  25"""
                           ))
Ejemplo n.º 4
0
def test_multi_index_update(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-09-08 17:06:11.040 |  EGG Index |  1.1
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-08 17:06:11.040 |  EGG Index |  2.1
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-10-09 17:06:11.040 |  EGG Index |  2.6
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0
                         2012-11-08 17:06:11.040 |  EGG Index |  3.1""",
                            num_index=2)
    ts2 = read_str_as_pandas("""          index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 | SPAM Index |  1.2
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-12-08 17:06:11.040 | SPAM Index |  4.0""",
                             num_index=2)
    expected_ts = read_str_as_pandas("""  index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-09-08 17:06:11.040 | SPAM Index |  1.2
                          2012-10-08 17:06:11.040 |  EGG Index |  2.1
                          2012-10-08 17:06:11.040 | SPAM Index |  2.0
                          2012-10-09 17:06:11.040 |  EGG Index |  2.6
                          2012-10-09 17:06:11.040 | SPAM Index |  2.5
                          2012-11-08 17:06:11.040 |  EGG Index |  3.1
                          2012-11-08 17:06:11.040 | SPAM Index |  3.0
                          2012-12-08 17:06:11.040 | SPAM Index |  4.0""",
                                     num_index=2)
    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)
Ejemplo n.º 5
0
def test_read_ts_raw_all_version_ok(bitemporal_library):
    bitemporal_library.update('spam',
                              ts1,
                              as_of=dt(2015, 5, 1, tzinfo=mktz('UTC')))
    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""
                                                 ),
                              as_of=dt(2015, 5, 5, tzinfo=mktz('UTC')))
    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-11-08 17:06:11.040 | 42"""
                                                 ),
                              as_of=dt(2015, 5, 3, tzinfo=mktz('UTC')))
    bitemporal_library.update('spam',
                              read_str_as_pandas("""           sample_dt | near
                                                         2012-10-08 17:06:11.040 | 42
                                                         2013-01-01 17:06:11.040 | 100"""
                                                 ),
                              as_of=dt(2015, 5, 10, tzinfo=mktz('UTC')))
    assert_frame_equal(
        bitemporal_library.read('spam', raw=True).data,
        read_str_as_pandas(
            """                    sample_dt | observed_dt | near
                                                      2012-09-08 17:06:11.040 |  2015-05-01 |  1.0
                                                      2012-10-08 17:06:11.040 |  2015-05-01 |  2.0
                                                      2012-10-08 17:06:11.040 |  2015-05-10 |  42
                                                      2012-10-09 17:06:11.040 |  2015-05-01 |  2.5
                                                      2012-11-08 17:06:11.040 |  2015-05-01 |  3.0
                                                      2012-11-08 17:06:11.040 |  2015-05-03 |  42
                                                      2012-12-01 17:06:11.040 |  2015-05-05 |  25
                                                      2013-01-01 17:06:11.040 |  2015-05-10 |  100""",
            num_index=2))
Ejemplo n.º 6
0
def test_read_ts_with_historical_update(bitemporal_library):
    with patch('arctic.store.bitemporal_store.dt') as mock_dt:
        mock_dt.now.return_value = dt(2015, 5, 1)
        mock_dt.side_effect = lambda *args, **kwargs: dt(*args, **kwargs)
        bitemporal_library.update('spam', ts1)

    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 | 4.2"""),
                              as_of=dt(2015, 5, 2))

    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 | 6.6"""),
                              as_of=dt(2015, 5, 3))
    assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 2, 10, tzinfo=pytz.timezone("Europe/London"))).data, read_str_as_pandas(
                                                                                    """sample_dt   | near
                                                                           2012-09-08 17:06:11.040 |  1.0
                                                                           2012-10-08 17:06:11.040 |  2.0
                                                                           2012-10-09 17:06:11.040 |  4.2
                                                                           2012-11-08 17:06:11.040 |  3.0"""))

    assert_frame_equal(bitemporal_library.read('spam').data, read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  6.6
                                                                       2012-11-08 17:06:11.040 |  3.0"""))

    assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 1, 10, tzinfo=pytz.timezone("Europe/London"))).data, ts1)
Ejemplo n.º 7
0
def test_read_ts_with_historical_update_and_new_row(bitemporal_library):
    with patch("arctic.store.bitemporal_store.dt") as mock_dt:
        mock_dt.now.return_value = dt(2015, 5, 1)
        mock_dt.side_effect = lambda *args, **kwargs: dt(*args, **kwargs)
        bitemporal_library.update("spam", ts1)

    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-10-09 17:06:11.040 | 4.2
                                                         2012-12-01 17:06:11.040 | 100"""
        ),
        as_of=dt(2015, 5, 2),
    )

    assert_frame_equal(
        bitemporal_library.read("spam").data,
        read_str_as_pandas(
            """  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  4.2
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""
        ),
    )

    assert_frame_equal(bitemporal_library.read("spam", as_of=dt(2015, 5, 1, 10)).data, ts1)
Ejemplo n.º 8
0
def test_multi_index_update(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-09-08 17:06:11.040 |  EGG Index |  1.1
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-08 17:06:11.040 |  EGG Index |  2.1
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-10-09 17:06:11.040 |  EGG Index |  2.6
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0
                         2012-11-08 17:06:11.040 |  EGG Index |  3.1""", num_index=2)
    ts2 = read_str_as_pandas("""          index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 | SPAM Index |  1.2
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-12-08 17:06:11.040 | SPAM Index |  4.0""", num_index=2)
    expected_ts = read_str_as_pandas("""  index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-09-08 17:06:11.040 | SPAM Index |  1.2
                          2012-10-08 17:06:11.040 |  EGG Index |  2.1
                          2012-10-08 17:06:11.040 | SPAM Index |  2.0
                          2012-10-09 17:06:11.040 |  EGG Index |  2.6
                          2012-10-09 17:06:11.040 | SPAM Index |  2.5
                          2012-11-08 17:06:11.040 |  EGG Index |  3.1
                          2012-11-08 17:06:11.040 | SPAM Index |  3.0
                          2012-12-08 17:06:11.040 | SPAM Index |  4.0""", num_index=2)
    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_existing_ts_update_existing_data_and_read(bitemporal_library):
    bitemporal_library.update('spam', ts1)
    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 |  4.2"""))
    expected_ts = read_str_as_pandas("""         sample_dt | near
                                     2012-09-08 17:06:11.040 |  1.0
                                     2012-10-08 17:06:11.040 |  2.0
                                     2012-10-09 17:06:11.040 |  4.2
                                     2012-11-08 17:06:11.040 |  3.0""")
    assert_frame_equal(expected_ts, bitemporal_library.read('spam').data)
Ejemplo n.º 10
0
def test_existing_ts_update_existing_data_and_read(bitemporal_library):
    bitemporal_library.update('spam', ts1)
    bitemporal_library.update('spam', read_str_as_pandas("""         sample_dt | near
                                                         2012-10-09 17:06:11.040 |  4.2"""))
    expected_ts = read_str_as_pandas("""         sample_dt | near
                                     2012-09-08 17:06:11.040 |  1.0
                                     2012-10-08 17:06:11.040 |  2.0
                                     2012-10-09 17:06:11.040 |  4.2
                                     2012-11-08 17:06:11.040 |  3.0""")
    assert_frame_equal(expected_ts, bitemporal_library.read('spam').data)
Ejemplo n.º 11
0
def test_insert_new_rows_in_middle_remains_sorted(bitemporal_library):
    bitemporal_library.update('spam', ts1)
    bitemporal_library.update('spam', read_str_as_pandas("""           sample_dt | near
                                                         2012-10-09 12:00:00.000 | 30.0
                                                         2012-12-01 17:06:11.040 | 100"""))

    assert_frame_equal(bitemporal_library.read('spam').data, read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 12:00:00.000 | 30.0
                                                                       2012-10-09 17:06:11.040 |  2.5
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""))
def test_insert_new_rows_in_middle_remains_sorted(bitemporal_library):
    bitemporal_library.update('spam', ts1)
    bitemporal_library.update('spam', read_str_as_pandas("""           sample_dt | near
                                                         2012-10-09 12:00:00.000 | 30.0
                                                         2012-12-01 17:06:11.040 | 100"""))

    assert_frame_equal(bitemporal_library.read('spam').data, read_str_as_pandas("""  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 12:00:00.000 | 30.0
                                                                       2012-10-09 17:06:11.040 |  2.5
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""))
Ejemplo n.º 13
0
def test_multi_index_ts_read_raw(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0""", num_index=2)

    expected_ts = read_str_as_pandas(""" index 1 |    index 2 | observed_dt | near
                         2012-09-08 17:06:11.040 | SPAM Index |  2015-01-01 |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2015-01-01 |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2015-01-01 |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  2015-01-01 |  3.0""", num_index=3)
    bitemporal_library.update('spam', ts, as_of=dt(2015, 1, 1))
    assert_frame_equal(expected_ts, bitemporal_library.read('spam', raw=True).data)
Ejemplo n.º 14
0
def test_multi_index_ts_read_raw(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0""", num_index=2)

    expected_ts = read_str_as_pandas(""" index 1 |    index 2 | observed_dt | near
                         2012-09-08 17:06:11.040 | SPAM Index |  2015-01-01 |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2015-01-01 |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2015-01-01 |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  2015-01-01 |  3.0""", num_index=3)
    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)
Ejemplo n.º 15
0
def test_bitemporal_store_read_as_of_timezone(bitemporal_library):
    bitemporal_library.update('spam', ts1, as_of=dt(2015, 5, 1, tzinfo=mktz('Europe/London')))
    bitemporal_library.update('spam', read_str_as_pandas("""           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""),
                              as_of=dt(2015, 5, 2, tzinfo=mktz('Europe/London')))
    df = bitemporal_library.read('spam', as_of=dt(2015, 5, 2, tzinfo=mktz('Asia/Hong_Kong'))).data
    assert_frame_equal(df, ts1)
def test_bitemporal_store_read_as_of_timezone(bitemporal_library):
    bitemporal_library.update('spam', ts1, as_of=dt(2015, 5, 1, tzinfo=mktz('Europe/London')))
    bitemporal_library.update('spam', read_str_as_pandas("""           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""),
                              as_of=dt(2015, 5, 2, tzinfo=mktz('Europe/London')))
    df = bitemporal_library.read('spam', as_of=dt(2015, 5, 2, tzinfo=mktz('Asia/Hong_Kong'))).data
    assert_frame_equal(df, ts1)
Ejemplo n.º 17
0
def test_add_observe_dt_index():
    self = create_autospec(BitemporalStore, observe_column='col_a')
    assert_frame_equal(BitemporalStore._add_observe_dt_index(self, ts1, as_of=dt(2001, 1, 1)),
                       read_str_as_pandas("""sample_dt |      col_a | near
                               2012-09-08 17:06:11.040 | 2001-01-01 |  1.0
                               2012-10-08 17:06:11.040 | 2001-01-01 |  2.0
                               2012-10-09 17:06:11.040 | 2001-01-01 |  2.5
                               2012-11-08 17:06:11.040 | 2001-01-01 |  3.0""", num_index=2))
Ejemplo n.º 18
0
def test_read_ts_raw(bitemporal_library):
    bitemporal_library.update('spam', ts1, as_of=dt(2015, 5, 1, tzinfo=mktz('UTC')))
    assert_frame_equal(bitemporal_library.read('spam', raw=True).data, read_str_as_pandas(
                                             """                    sample_dt | observed_dt | near
                                                      2012-09-08 17:06:11.040 |  2015-05-01 |  1.0
                                                      2012-10-08 17:06:11.040 |  2015-05-01 |  2.0
                                                      2012-10-09 17:06:11.040 |  2015-05-01 |  2.5
                                                      2012-11-08 17:06:11.040 |  2015-05-01 |  3.0""", num_index=2))
Ejemplo n.º 19
0
def test_multi_index_ts_read_write(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0""", num_index=2)
    bitemporal_library.update('spam', ts)
    assert_frame_equal(ts, bitemporal_library.read('spam').data)
Ejemplo n.º 20
0
def test_write_ts_with_column_name_same_as_observed_dt_ok(bitemporal_library):
    ts1 = read_str_as_pandas("""       sample_dt | observed_dt | near
                         2012-09-08 17:06:11.040 |    2015-1-1 |  1.0
                         2012-10-08 17:06:11.040 |    2015-1-1 |  2.0
                         2012-10-09 17:06:11.040 |    2015-1-1 |  2.5
                         2012-11-08 17:06:11.040 |    2015-1-1 |  3.0""")
    bitemporal_library.update('spam', ts1)
    assert_frame_equal(ts1, bitemporal_library.read('spam').data)
Ejemplo n.º 21
0
def test_write_ts_with_column_name_same_as_observed_dt_ok(bitemporal_library):
    ts1 = read_str_as_pandas("""       sample_dt | observed_dt | near
                         2012-09-08 17:06:11.040 |    2015-1-1 |  1.0
                         2012-10-08 17:06:11.040 |    2015-1-1 |  2.0
                         2012-10-09 17:06:11.040 |    2015-1-1 |  2.5
                         2012-11-08 17:06:11.040 |    2015-1-1 |  3.0""")
    bitemporal_library.update('spam', ts1)
    assert_frame_equal(ts1, bitemporal_library.read('spam').data)
Ejemplo n.º 22
0
def test_multi_index_ts_read_write(bitemporal_library):
    ts = read_str_as_pandas("""          index 1 |    index 2 | near
                         2012-09-08 17:06:11.040 | SPAM Index |  1.0
                         2012-10-08 17:06:11.040 | SPAM Index |  2.0
                         2012-10-09 17:06:11.040 | SPAM Index |  2.5
                         2012-11-08 17:06:11.040 | SPAM Index |  3.0""", num_index=2)
    bitemporal_library.update('spam', ts)
    assert_frame_equal(ts, bitemporal_library.read('spam').data)
Ejemplo n.º 23
0
def test_insert_versions_inbetween_works_ok(bitemporal_library):
    bitemporal_library.update("spam", ts1, as_of=dt(2015, 5, 1))
    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 100"""
        ),
        as_of=dt(2015, 5, 10),
    )

    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""
        ),
        as_of=dt(2015, 5, 8),
    )

    assert_frame_equal(
        bitemporal_library.read("spam").data,
        read_str_as_pandas(
            """  sample_dt | near
                                                                       2012-09-08 17:06:11.040 |  1.0
                                                                       2012-10-08 17:06:11.040 |  2.0
                                                                       2012-10-09 17:06:11.040 |  2.5
                                                                       2012-11-08 17:06:11.040 |  3.0
                                                                       2012-12-01 17:06:11.040 |  100"""
        ),
    )

    assert_frame_equal(
        bitemporal_library.read("spam", as_of=dt(2015, 5, 9)).data,
        read_str_as_pandas(
            """  sample_dt | near
                                                                     2012-09-08 17:06:11.040 |  1.0
                                                                     2012-10-08 17:06:11.040 |  2.0
                                                                     2012-10-09 17:06:11.040 |  2.5
                                                                     2012-11-08 17:06:11.040 |  3.0
                                                                     2012-12-01 17:06:11.040 |  25"""
        ),
    )
Ejemplo n.º 24
0
def test_fancy_group_by_multi_index():
    ts = read_str_as_pandas("""      index 1 |    index 2 | observed_dt | near
                     2012-09-08 17:06:11.040 | SPAM Index | 2015-01-01 |  1.0
                     2012-09-08 17:06:11.040 |  EGG Index | 2015-01-01 |  1.6
                     2012-10-08 17:06:11.040 | SPAM Index | 2015-01-01 |  2.0
                     2012-10-08 17:06:11.040 | SPAM Index | 2015-01-05 |  4.2
                     2012-10-08 17:06:11.040 |  EGG Index | 2015-01-01 |  2.1
                     2012-10-09 17:06:11.040 | SPAM Index | 2015-01-01 |  2.5
                     2012-10-09 17:06:11.040 |  EGG Index | 2015-01-01 |  2.6
                     2012-11-08 17:06:11.040 | SPAM Index | 2015-01-01 |  3.0""", num_index=3)
    expected_ts = read_str_as_pandas("""  index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-09-08 17:06:11.040 | SPAM Index |  1.0
                          2012-10-08 17:06:11.040 |  EGG Index |  2.1
                          2012-10-08 17:06:11.040 | SPAM Index |  4.2
                          2012-10-09 17:06:11.040 |  EGG Index |  2.6
                          2012-10-09 17:06:11.040 | SPAM Index |  2.5
                          2012-11-08 17:06:11.040 | SPAM Index |  3.0""", num_index=2)
    assert_frame_equal(expected_ts, groupby_asof(ts, dt_col=['index 1', 'index 2'], asof_col='observed_dt'))
Ejemplo n.º 25
0
def test_read_ts_raw_all_version_ok(bitemporal_library):
    bitemporal_library.update("spam", ts1, as_of=dt(2015, 5, 1, tzinfo=mktz("UTC")))
    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-12-01 17:06:11.040 | 25"""
        ),
        as_of=dt(2015, 5, 5, tzinfo=mktz("UTC")),
    )
    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-11-08 17:06:11.040 | 42"""
        ),
        as_of=dt(2015, 5, 3, tzinfo=mktz("UTC")),
    )
    bitemporal_library.update(
        "spam",
        read_str_as_pandas(
            """           sample_dt | near
                                                         2012-10-08 17:06:11.040 | 42
                                                         2013-01-01 17:06:11.040 | 100"""
        ),
        as_of=dt(2015, 5, 10, tzinfo=mktz("UTC")),
    )
    assert_frame_equal(
        bitemporal_library.read("spam", raw=True).data.tz_localize(tz=None, level=1),
        read_str_as_pandas(
            """                    sample_dt | observed_dt | near
                                                      2012-09-08 17:06:11.040 |  2015-05-01 |  1.0
                                                      2012-10-08 17:06:11.040 |  2015-05-01 |  2.0
                                                      2012-10-08 17:06:11.040 |  2015-05-10 |  42
                                                      2012-10-09 17:06:11.040 |  2015-05-01 |  2.5
                                                      2012-11-08 17:06:11.040 |  2015-05-01 |  3.0
                                                      2012-11-08 17:06:11.040 |  2015-05-03 |  42
                                                      2012-12-01 17:06:11.040 |  2015-05-05 |  25
                                                      2013-01-01 17:06:11.040 |  2015-05-10 |  100""",
            num_index=2,
        ),
    )
Ejemplo n.º 26
0
def test_read_ts_raw(bitemporal_library):
    bitemporal_library.update("spam", ts1, as_of=dt(2015, 5, 1, tzinfo=mktz("UTC")))
    assert_frame_equal(
        bitemporal_library.read("spam", raw=True).data.tz_convert(tz=mktz("UTC"), level=1),
        read_str_as_pandas(
            """                    sample_dt | observed_dt | near
                                                      2012-09-08 17:06:11.040 |  2015-05-01 |  1.0
                                                      2012-10-08 17:06:11.040 |  2015-05-01 |  2.0
                                                      2012-10-09 17:06:11.040 |  2015-05-01 |  2.5
                                                      2012-11-08 17:06:11.040 |  2015-05-01 |  3.0""",
            num_index=2,
        ).tz_localize(tz=mktz("UTC"), level=1),
    )
def test_read_multi_index_with_no_ts_info():
    # github #81: old multi-index ts would not have tz info in metadata. Ensure read is not broken
    df = read_str_as_pandas("""index 1 |    index 2 | SPAM
                            2012-09-08 | 2015-01-01 |  1.0
                            2012-09-09 | 2015-01-02 |  1.1
                            2012-10-08 | 2015-01-03 |  2.0""", num_index=2)
    store = PandasDataFrameStore()
    record = store.SERIALIZER.serialize(df)[0]

    # now take away timezone info from metadata
    record = np.array(record.tolist(), dtype=np.dtype([('index 1', '<M8[ns]'), ('index 2', '<M8[ns]'), ('SPAM', '<f8')],
                                                      metadata={'index': ['index 1', 'index 2'], 'columns': ['SPAM']}))
    assert store.SERIALIZER._index_from_records(record).equals(df.index)
Ejemplo n.º 28
0
def test_read_multi_index_with_no_ts_info():
    # github #81: old multi-index ts would not have tz info in metadata. Ensure read is not broken
    df = read_str_as_pandas("""index 1 |    index 2 | SPAM
                            2012-09-08 | 2015-01-01 |  1.0
                            2012-09-09 | 2015-01-02 |  1.1
                            2012-10-08 | 2015-01-03 |  2.0""", num_index=2)
    store = PandasDataFrameStore()
    record = store.SERIALIZER.serialize(df)[0]

    # now take away timezone info from metadata
    record = np.array(record.tolist(), dtype=np.dtype([('index 1', '<M8[ns]'), ('index 2', '<M8[ns]'), ('SPAM', '<f8')],
                                                      metadata={'index': ['index 1', 'index 2'], 'columns': ['SPAM']}))
    assert store.SERIALIZER._index_from_records(record).equals(df.index)
Ejemplo n.º 29
0
def test_fancy_group_by_multi_index():
    ts = read_str_as_pandas("""      index 1 |    index 2 | observed_dt | near
                     2012-09-08 17:06:11.040 | SPAM Index | 2015-01-01 |  1.0
                     2012-09-08 17:06:11.040 |  EGG Index | 2015-01-01 |  1.6
                     2012-10-08 17:06:11.040 | SPAM Index | 2015-01-01 |  2.0
                     2012-10-08 17:06:11.040 | SPAM Index | 2015-01-05 |  4.2
                     2012-10-08 17:06:11.040 |  EGG Index | 2015-01-01 |  2.1
                     2012-10-09 17:06:11.040 | SPAM Index | 2015-01-01 |  2.5
                     2012-10-09 17:06:11.040 |  EGG Index | 2015-01-01 |  2.6
                     2012-11-08 17:06:11.040 | SPAM Index | 2015-01-01 |  3.0""",
                            num_index=3)
    expected_ts = read_str_as_pandas("""  index 1 |    index 2 | near
                          2012-09-08 17:06:11.040 |  EGG Index |  1.6
                          2012-09-08 17:06:11.040 | SPAM Index |  1.0
                          2012-10-08 17:06:11.040 |  EGG Index |  2.1
                          2012-10-08 17:06:11.040 | SPAM Index |  4.2
                          2012-10-09 17:06:11.040 |  EGG Index |  2.6
                          2012-10-09 17:06:11.040 | SPAM Index |  2.5
                          2012-11-08 17:06:11.040 | SPAM Index |  3.0""",
                                     num_index=2)
    assert_frame_equal(
        expected_ts,
        groupby_asof(ts, dt_col=['index 1', 'index 2'],
                     asof_col='observed_dt'))
Ejemplo n.º 30
0
def test_read_ts_raw(bitemporal_library):
    bitemporal_library.update('spam',
                              ts1,
                              as_of=dt(2015, 5, 1, tzinfo=mktz('UTC')))
    assert_frame_equal(
        bitemporal_library.read('spam',
                                raw=True).data.tz_convert(tz=mktz('UTC'),
                                                          level=1),
        read_str_as_pandas(
            """                    sample_dt | observed_dt | near
                                                      2012-09-08 17:06:11.040 |  2015-05-01 |  1.0
                                                      2012-10-08 17:06:11.040 |  2015-05-01 |  2.0
                                                      2012-10-09 17:06:11.040 |  2015-05-01 |  2.5
                                                      2012-11-08 17:06:11.040 |  2015-05-01 |  3.0""",
            num_index=2).tz_localize(tz=mktz('UTC'), level=1))
Ejemplo n.º 31
0
@author: ateng
'''
from datetime import datetime as dt

from mock import patch
from pandas.util.testing import assert_frame_equal

from arctic.date._mktz import mktz
import pandas as pd
from tests.util import read_str_as_pandas

pytest_plugins = ['arctic.fixtures.arctic']

ts1 = read_str_as_pandas("""           sample_dt | near
                         2012-09-08 17:06:11.040 |  1.0
                         2012-10-08 17:06:11.040 |  2.0
                         2012-10-09 17:06:11.040 |  2.5
                         2012-11-08 17:06:11.040 |  3.0""")

ts1_update = read_str_as_pandas("""           sample_dt | near
                                2012-09-08 17:06:11.040 |  1.0
                                2012-10-08 17:06:11.040 |  2.0
                                2012-10-09 17:06:11.040 |  2.5
                                2012-11-08 17:06:11.040 |  3.0
                                2012-11-09 17:06:11.040 |  3.5""")

LOCAL_TZ = mktz()


def test_new_ts_read_write(bitemporal_library):
    bitemporal_library.update('spam', ts1)
Ejemplo n.º 32
0
'''
from datetime import datetime as dt

import pytz
from mock import patch
from pandas.util.testing import assert_frame_equal

from arctic.date._mktz import mktz
from tests.util import read_str_as_pandas, multi_index_df_from_arrs

pytest_plugins = ['arctic.fixtures.arctic']


ts1 = read_str_as_pandas("""           sample_dt | near
                         2012-09-08 17:06:11.040 |  1.0
                         2012-10-08 17:06:11.040 |  2.0
                         2012-10-09 17:06:11.040 |  2.5
                         2012-11-08 17:06:11.040 |  3.0""")

ts1_update = read_str_as_pandas("""           sample_dt | near
                                2012-09-08 17:06:11.040 |  1.0
                                2012-10-08 17:06:11.040 |  2.0
                                2012-10-09 17:06:11.040 |  2.5
                                2012-11-08 17:06:11.040 |  3.0
                                2012-11-09 17:06:11.040 |  3.5""")

LOCAL_TZ = mktz()


def test_new_ts_read_write(bitemporal_library):
    bitemporal_library.update('spam', ts1)