Skip to content

Commit

Permalink
Merge a20696e into 15fe38c
Browse files Browse the repository at this point in the history
  • Loading branch information
llllllllll committed Jul 19, 2017
2 parents 15fe38c + a20696e commit 869831d
Show file tree
Hide file tree
Showing 15 changed files with 1,911 additions and 750 deletions.
5 changes: 5 additions & 0 deletions setup.py
Expand Up @@ -115,6 +115,11 @@ def window_specialization(typename):
'zipline.data._resample',
['zipline/data/_resample.pyx']
),
Extension(
'zipline.pipeline.loaders.blaze._core',
['zipline/pipeline/loaders/blaze/_core.pyx'],
depends=['zipline/lib/adjustment.pxd'],
),
]


Expand Down
539 changes: 247 additions & 292 deletions tests/pipeline/test_blaze.py

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions tests/pipeline/test_classifier.py
@@ -1,11 +1,12 @@
from functools import reduce
from operator import or_
import operator as op

import numpy as np
import pandas as pd

from zipline.lib.labelarray import LabelArray
from zipline.pipeline import Classifier
from zipline.pipeline.expression import methods_to_ops
from zipline.testing import parameter_space
from zipline.testing.fixtures import ZiplineTestCase
from zipline.testing.predicates import assert_equal
Expand Down Expand Up @@ -404,7 +405,7 @@ class C(Classifier):
for choices in [(0,), (0, 1), (0, 1, 2)]:
terms[str(choices)] = c.element_of(choices)
expected[str(choices)] = reduce(
or_,
op.or_,
(data == elem for elem in choices),
np.zeros_like(data, dtype=bool),
)
Expand Down Expand Up @@ -584,6 +585,27 @@ class C(Classifier):
)
self.assertEqual(result, expected)

@parameter_space(
compare_op=[op.gt, op.ge, op.le, op.lt],
dtype_and_missing=[(int64_dtype, 0), (categorical_dtype, '')],
)
def test_bad_compare(self, compare_op, dtype_and_missing):
class C(Classifier):
inputs = ()
window_length = 0
dtype = dtype_and_missing[0]
missing_value = dtype_and_missing[1]

with self.assertRaises(TypeError) as e:
compare_op(C(), object())

self.assertEqual(
str(e.exception),
'cannot compare classifiers with %s' % (
methods_to_ops['__%s__' % compare_op.__name__],
),
)


class TestPostProcessAndToWorkSpaceValue(ZiplineTestCase):
def test_reversability_categorical(self):
Expand Down
4 changes: 2 additions & 2 deletions zipline/lib/adjusted_array.py
Expand Up @@ -35,7 +35,7 @@

NOMASK = None
BOOL_DTYPES = frozenset(
map(dtype, [bool_]),
map(dtype, [bool_, uint8]),
)
FLOAT_DTYPES = frozenset(
map(dtype, [float32, float64]),
Expand Down Expand Up @@ -103,7 +103,7 @@ def _normalize_array(data, missing_value):
return data, {}

data_dtype = data.dtype
if data_dtype == bool_:
if data_dtype in BOOL_DTYPES:
return data.astype(uint8), {'dtype': dtype(bool_)}
elif data_dtype in FLOAT_DTYPES:
return data.astype(float64), {'dtype': dtype(float64)}
Expand Down

0 comments on commit 869831d

Please sign in to comment.