本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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"""))
示例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)
示例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)
示例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))
示例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))
示例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)
示例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)
示例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'))
示例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"""
),
)
示例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,
),
)
示例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)