當前位置: 首頁>>代碼示例>>Python>>正文


Python toplevel.TopLevelTickStore類代碼示例

本文整理匯總了Python中arctic.tickstore.toplevel.TopLevelTickStore的典型用法代碼示例。如果您正苦於以下問題:Python TopLevelTickStore類的具體用法?Python TopLevelTickStore怎麽用?Python TopLevelTickStore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TopLevelTickStore類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_slice_pandas_dataframe

def test_slice_pandas_dataframe(start, end, expected_start_index, expected_end_index):
    top_level_tick_store = TopLevelTickStore(Mock())
    dates = pd.date_range("20100101", periods=5, freq="2D")
    data = pd.DataFrame(np.random.randn(5, 4), index=dates, columns=list("ABCD"))
    expected = data.ix[expected_start_index:expected_end_index]
    result = top_level_tick_store._slice(data, start, end)
    assert_frame_equal(expected, result), "{}\n{}".format(expected, result)
開發者ID:rsheftel,項目名稱:arctic,代碼行數:7,代碼來源:test_toplevel.py

示例2: test_slice_list_of_dicts

def test_slice_list_of_dicts(start, end, expected_start_index, expected_end_index):
    top_level_tick_store = TopLevelTickStore(Mock())
    dates = list(rrule(DAILY, count=5, dtstart=dt(2010, 1, 1), interval=2))
    data = [{"index": date, "A": val} for date, val in zip(dates, range(5))]
    expected = data[expected_start_index:expected_end_index]
    result = top_level_tick_store._slice(data, start, end)
    assert expected == result
開發者ID:rsheftel,項目名稱:arctic,代碼行數:7,代碼來源:test_toplevel.py

示例3: test_raise_exception_and_log_an_error_if_an_invalid_library_name_is_added

def test_raise_exception_and_log_an_error_if_an_invalid_library_name_is_added():
    arctic_lib = MagicMock()
    arctic_lib.arctic.__getitem__.side_effect = Exception()
    store = TopLevelTickStore(arctic_lib)
    with patch("arctic.tickstore.toplevel.logger") as mock_logger:
        with pytest.raises(Exception):
            store.add(None, "blah")
    mock_logger.error.assert_called_once_with("Could not load library")
開發者ID:rsheftel,項目名稱:arctic,代碼行數:8,代碼來源:test_toplevel.py

示例4: test_add_library_to_colllection_if_date_range_is_on_UTC_or_naive_day_boundaries

def test_add_library_to_colllection_if_date_range_is_on_UTC_or_naive_day_boundaries(start, end, expected_start, expected_end):
    self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock(), _collection=MagicMock())
    self._get_library_metadata.return_value = []
    TopLevelTickStore.add(self, DateRange(start=start, end=end), "blah")
    self._collection.update_one.assert_called_once_with({'library_name': "blah"},
                                                        {'$set':
                                                         {'start': expected_start,
                                                          'end': expected_end}}, upsert=True)
開發者ID:JianfengYu,項目名稱:arctic,代碼行數:8,代碼來源:test_toplevel.py

示例5: test_write_pandas_data_to_right_libraries

def test_write_pandas_data_to_right_libraries():
    self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock(), _collection=MagicMock())
    self._collection.find.return_value = [{'library_name': sentinel.libname1, 'start': sentinel.st1, 'end': sentinel.end1},
                                          {'library_name': sentinel.libname2, 'start': sentinel.st2, 'end': sentinel.end2}]
    slice1 = range(2)
    slice2 = range(4)
    when(self._slice).called_with(sentinel.data, sentinel.st1, sentinel.end1).then(slice1)
    when(self._slice).called_with(sentinel.data, sentinel.st2, sentinel.end2).then(slice2)
    mock_lib1 = Mock()
    mock_lib2 = Mock()
    when(self._arctic_lib.arctic.__getitem__).called_with(sentinel.libname1).then(mock_lib1)
    when(self._arctic_lib.arctic.__getitem__).called_with(sentinel.libname2).then(mock_lib2)
    TopLevelTickStore.write(self, 'blah', sentinel.data)
    mock_lib1.write.assert_called_once_with('blah', slice1)
    mock_lib2.write.assert_called_once_with('blah', slice2)
開發者ID:JianfengYu,項目名稱:arctic,代碼行數:15,代碼來源:test_toplevel.py

示例6: test_read

def test_read():
    self = create_autospec(TopLevelTickStore)
    tsl = TickStoreLibrary(create_autospec(TickStore), create_autospec(DateRange))
    self._get_libraries.return_value = [tsl, tsl]
    dr = create_autospec(DateRange)
    with patch("pandas.concat") as concat:
        res = TopLevelTickStore.read(
            self, sentinel.symbol, dr, columns=sentinel.include_columns, include_images=sentinel.include_images
        )
    assert concat.call_args_list == [call([tsl.library.read.return_value, tsl.library.read.return_value])]
    assert res == concat.return_value
    assert tsl.library.read.call_args_list == [
        call(
            sentinel.symbol,
            tsl.date_range.intersection.return_value,
            sentinel.include_columns,
            include_images=sentinel.include_images,
        ),
        call(
            sentinel.symbol,
            tsl.date_range.intersection.return_value,
            sentinel.include_columns,
            include_images=sentinel.include_images,
        ),
    ]
開發者ID:rsheftel,項目名稱:arctic,代碼行數:25,代碼來源:test_toplevel.py

示例7: test_raise_exception_if_date_range_overlaps

def test_raise_exception_if_date_range_overlaps():
    self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock())
    self._get_library_metadata.return_value = [TickStoreLibrary("lib1", None)]
    with pytest.raises(OverlappingDataException) as e:
        TopLevelTickStore.add(self, DateRange(start=dt(2010, 1, 1), end=dt(2011, 1, 1, 23, 59, 59, 999000)), "blah")
    assert "There are libraries that overlap with the date range:" in str(e)
開發者ID:rsheftel,項目名稱:arctic,代碼行數:6,代碼來源:test_toplevel.py

示例8: test_raise_exception_if_date_range_does_not_contain_start_and_end_date

def test_raise_exception_if_date_range_does_not_contain_start_and_end_date():
    store = TopLevelTickStore(Mock())
    dr = DateRange(start=None, end=None)
    with pytest.raises(Exception) as e:
        store._get_library_metadata(dr)
    assert "The date range {0} must contain a start and end date".format(dr) in str(e)
開發者ID:rsheftel,項目名稱:arctic,代碼行數:6,代碼來源:test_toplevel.py

示例9: test_raise_exception_if_daterange_is_not_provided

def test_raise_exception_if_daterange_is_not_provided():
    store = TopLevelTickStore(Mock())
    with pytest.raises(Exception) as e:
        store._get_library_metadata(None)
    assert "A date range must be provided" in str(e)
開發者ID:rsheftel,項目名稱:arctic,代碼行數:5,代碼來源:test_toplevel.py

示例10: test_raise_error_add_library_is_called_with_a_date_range_not_on_day_boundaries

def test_raise_error_add_library_is_called_with_a_date_range_not_on_day_boundaries(start, end):
    with pytest.raises(AssertionError) as e:
        self = create_autospec(TopLevelTickStore, _arctic_lib=MagicMock(), _collection=MagicMock())
        self._get_library_metadata.return_value = []
        TopLevelTickStore.add(self, DateRange(start=start, end=end), "blah")
    assert "Date range should fall on UTC day boundaries" in str(e)
開發者ID:rsheftel,項目名稱:arctic,代碼行數:6,代碼來源:test_toplevel.py

示例11: test_slice_raises

def test_slice_raises():
    m = TopLevelTickStore(Mock())
    with pytest.raises(UnhandledDtypeException) as e:
        m._slice("abc", 1, 2)
    assert("Can't persist type" in str(e))
開發者ID:JianfengYu,項目名稱:arctic,代碼行數:5,代碼來源:test_toplevel.py


注:本文中的arctic.tickstore.toplevel.TopLevelTickStore類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。