def test_doc_differentiates(self): a = sentinel('sentinel-name', 'original-doc') with self.assertRaises(ValueError) as e: sentinel(a.__name__, 'new-doc') msg = str(e.exception) self.assertIn(a.__name__, msg) self.assertIn(a.__doc__, msg)
class TestingSlippage(SlippageModel): """ Slippage model that fills a constant number of shares per tick, for testing purposes. Parameters ---------- filled_per_tick : int or TestingSlippage.ALL The number of shares to fill on each call to process_order. If TestingSlippage.ALL is passed, the entire order is filled. See also -------- catalyst.finance.slippage.SlippageModel """ ALL = sentinel('ALL') allowed_asset_types = (Equity, ) def __init__(self, filled_per_tick): super(TestingSlippage, self).__init__() self.filled_per_tick = filled_per_tick def process_order(self, data, order): price = data.current(order.asset, "close") if self.filled_per_tick is self.ALL: volume = order.amount else: volume = self.filled_per_tick return (price, volume)
class tmp_assets_db(object): """Create a temporary assets sqlite database. This is meant to be used as a context manager. Parameters ---------- url : string The URL for the database connection. **frames The frames to pass to the AssetDBWriter. By default this maps equities: ('A', 'B', 'C') -> map(ord, 'ABC') See Also -------- empty_assets_db tmp_asset_finder """ _default_equities = sentinel('_default_equities') def __init__(self, url='sqlite:///:memory:', equities=_default_equities, **frames): self._url = url self._eng = None if equities is self._default_equities: equities = make_simple_equity_info( list(map(ord, 'ABC')), pd.Timestamp(0), pd.Timestamp('2015'), ) frames['equities'] = equities self._frames = frames self._eng = None # set in enter and exit def __enter__(self): self._eng = eng = create_engine(self._url) AssetDBWriter(eng).write(**self._frames) return eng def __exit__(self, *excinfo): assert self._eng is not None, '_eng was not set in __enter__' self._eng.dispose() self._eng = None
def __init__(self, left, right): (mismatches,) = np.where(left != right) assert len(mismatches), "Not actually a mismatch!" super(CategoryMismatch, self).__init__( "LabelArray categories don't match:\n" "Mismatched Indices: {mismatches}\n" "Left: {left}\n" "Right: {right}".format( mismatches=mismatches, left=left[mismatches], right=right[mismatches], ) ) _NotPassed = sentinel('_NotPassed') class LabelArray(ndarray): """ An ndarray subclass for working with arrays of strings. Factorizes the input array into integers, but overloads equality on strings to check against the factor label. Parameters ---------- values : array-like Array of values that can be passed to np.asarray with dtype=object. missing_value : str Scalar value to treat as 'missing' for operations on ``self``.
def test_weakreferencable(self): ref(sentinel('a'))
def test_pickle_roundtrip(self): a = sentinel('a') self.assertIs(loads(dumps(a)), a)
def test_new(self): with self.assertRaises(TypeError): type(sentinel('a'))()
def test_repr(self): self.assertEqual( repr(sentinel('a')), "sentinel('a')", )
from catalyst.utils.sentinel import sentinel NotSpecified = sentinel( 'NotSpecified', 'Singleton sentinel value used for Term defaults.', ) NotSpecifiedType = type(NotSpecified)
def test_copy(self): a = sentinel('a') self.assertIs(copy(a), a)
def test_memo(self): self.assertIs(sentinel('a'), sentinel('a'))
def test_doc(self): self.assertEqual(sentinel('a', 'b').__doc__, 'b')
def test_name(self): self.assertEqual(sentinel('a').__name__, 'a')
class calendars(object): CRYPTO_ASSETS = sentinel('CRYPTO_ASSETS') US_EQUITIES = sentinel('US_EQUITIES') US_FUTURES = sentinel('US_FUTURES')
def test_deepcopy(self): a = sentinel('a') self.assertIs(deepcopy(a), a)
""" def __init__(self, left, right): (mismatches, ) = np.where(left != right) assert len(mismatches), "Not actually a mismatch!" super(CategoryMismatch, self).__init__("LabelArray categories don't match:\n" "Mismatched Indices: {mismatches}\n" "Left: {left}\n" "Right: {right}".format( mismatches=mismatches, left=left[mismatches], right=right[mismatches], )) _NotPassed = sentinel('_NotPassed') class LabelArray(ndarray): """ An ndarray subclass for working with arrays of strings. Factorizes the input array into integers, but overloads equality on strings to check against the factor label. Parameters ---------- values : array-like Array of values that can be passed to np.asarray with dtype=object. missing_value : str Scalar value to treat as 'missing' for operations on ``self``.
from catalyst.utils.sentinel import sentinel NotSpecified = sentinel( 'NotSpecified', 'Singleton sentinel value used for Term defaults.', ) NotSpecifiedType = type(NotSpecified)