zipline/tests/pipeline/test_alias.py
Scott Sanderson e491ebef53 ENH: Initial support for international pipelines.
This commit adds initial support for international markets in the Pipeline API
via addition of the concept of "domains".

Significant changes on this branch include:

- Added `zipline.pipeline.domain` and the `Domain` interface.
  - Added several canonical domain definitions:
    - GENERIC
    - US_EQUITIES
    - CA_EQUITIES
    - GB_EQUITIES

- Added `zipline.country` as a place to define canonical country code names.

- Made `PipelineLoader` an interface and added new `domain` parameter to
  signature of `load_adjusted_array`.

- Added a new system for "generic" and "specialized" DataSet and BoundColumn
  objects.

- Added a new system for inferring a domain from a pipeline that contains a mix
  of generic and non-generic terms.

- Reworked the built-in pricing dataset. USEquityPricing dataset is now a
  specialized version of a generic EquityPricing dataset, and most built-in
  factors are now implemented in terms of EquityPricing rather than
  USEquityPricing.

- Removed `zipline.data.us_equity_pricing`.
  - Moved BcolzDailyBar{Reader,Writer} to `zipline.data.bcolz_daily_bars`.
  - Moved SQLiteAdjustment{Reader,Writer} to `zipline.data.adjustments`.

New dependencies added as part of this work:

- iso3166 (for canonical country code definitions)
- python-interface (for strict interface definitions).

See https://github.com/quantopian/zipline/issues/2265 for a full description of
the design for domains.
2018-09-10 10:05:39 -05:00

65 lines
1.6 KiB
Python

from nose.tools import nottest
import numpy as np
from zipline.testing.predicates import assert_equal
from zipline.pipeline import Classifier, Factor, Filter
from zipline.utils.numpy_utils import float64_dtype, int64_dtype
from .base import BaseUSEquityPipelineTestCase
@nottest
class BaseAliasTestCase(BaseUSEquityPipelineTestCase):
def test_alias(self):
f = self.Term()
alias = f.alias('ayy lmao')
f_values = np.random.RandomState(5).randn(5, 5)
self.check_terms(
terms={
'f_alias': alias,
},
expected={
'f_alias': f_values,
},
initial_workspace={f: f_values},
mask=self.build_mask(np.ones((5, 5))),
)
def test_repr(self):
assert_equal(
repr(self.Term().alias('ayy lmao')),
"Aliased%s(Term(...), name='ayy lmao')" % (
self.Term.__base__.__name__,
),
)
def test_graph_repr(self):
for name in ('a', 'b'):
assert_equal(
self.Term().alias(name).graph_repr(),
name,
)
class TestFactorAlias(BaseAliasTestCase):
class Term(Factor):
dtype = float64_dtype
inputs = ()
window_length = 0
class TestFilterAlias(BaseAliasTestCase):
class Term(Filter):
inputs = ()
window_length = 0
class TestClassifierAlias(BaseAliasTestCase):
class Term(Classifier):
dtype = int64_dtype
inputs = ()
window_length = 0
missing_value = -1