• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.read_str_as_pandas函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.util.read_str_as_pandas函数的典型用法代码示例。如果您正苦于以下问题:Python read_str_as_pandas函数的具体用法?Python read_str_as_pandas怎么用?Python read_str_as_pandas使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了read_str_as_pandas函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_read_ts_with_historical_update

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)
开发者ID:manahl,项目名称:arctic,代码行数:27,代码来源:test_bitemporal_store.py


示例2: test_read_ts_with_historical_update_and_new_row

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)
开发者ID:r0k3,项目名称:arctic,代码行数:29,代码来源:test_bitemporal_store.py


示例3: test_multi_index_update

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)
开发者ID:gcustomair,项目名称:arctic,代码行数:28,代码来源:test_bitemporal_store.py


示例4: test_existing_ts_update_existing_data_and_read

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)
开发者ID:manahl,项目名称:arctic,代码行数:10,代码来源:test_bitemporal_store.py


示例5: test_insert_new_rows_in_middle_remains_sorted

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"""))
开发者ID:manahl,项目名称:arctic,代码行数:13,代码来源:test_bitemporal_store.py


示例6: test_multi_index_ts_read_raw

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)
开发者ID:gcustomair,项目名称:arctic,代码行数:14,代码来源:test_bitemporal_store.py


示例7: test_bitemporal_store_read_as_of_timezone

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)
开发者ID:manahl,项目名称:arctic,代码行数:7,代码来源:test_bitemporal_store.py


示例8: test_read_ts_raw

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))
开发者ID:gcustomair,项目名称:arctic,代码行数:8,代码来源:test_bitemporal_store.py


示例9: test_add_observe_dt_index

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))
开发者ID:manahl,项目名称:arctic,代码行数:8,代码来源:test_bitemporal_store.py


示例10: test_multi_index_ts_read_write

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)
开发者ID:gcustomair,项目名称:arctic,代码行数:8,代码来源:test_bitemporal_store.py


示例11: test_write_ts_with_column_name_same_as_observed_dt_ok

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)
开发者ID:manahl,项目名称:arctic,代码行数:8,代码来源:test_bitemporal_store.py


示例12: test_fancy_group_by_multi_index

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'))
开发者ID:bigtonylewis,项目名称:arctic,代码行数:19,代码来源:test_multi_index.py


示例13: test_insert_versions_inbetween_works_ok

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"""
        ),
    )
开发者ID:r0k3,项目名称:arctic,代码行数:43,代码来源:test_bitemporal_store.py


示例14: test_read_ts_raw_all_version_ok

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,
        ),
    )
开发者ID:r0k3,项目名称:arctic,代码行数:42,代码来源:test_bitemporal_store.py


示例15: test_read_multi_index_with_no_ts_info

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)
开发者ID:manahl,项目名称:arctic,代码行数:13,代码来源:test_pandas_ndarray_store.py


示例16: test_read_ts_raw

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),
    )
开发者ID:r0k3,项目名称:arctic,代码行数:13,代码来源:test_bitemporal_store.py


示例17: read_str_as_pandas

'''
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)
开发者ID:manahl,项目名称:arctic,代码行数:31,代码来源:test_bitemporal_store.py



注:本文中的tests.util.read_str_as_pandas函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.runProgram函数代码示例发布时间:2022-05-27
下一篇:
Python util.poll_until函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap