Skip to content

Commit

Permalink
Merge 2c81e42 into 4fa39ac
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhbromley committed Sep 20, 2019
2 parents 4fa39ac + 2c81e42 commit 31c940f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/pipeline/test_column.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""
Tests BoundColumn attributes and methods.
"""
import operator
from unittest import skipIf

from nose_parameterized import parameterized
from pandas import Timestamp, DataFrame
from pandas.util.testing import assert_frame_equal

from zipline.lib.labelarray import LabelArray
from zipline.pipeline import Pipeline
from zipline.pipeline.data import USEquityPricing
from zipline.pipeline.data.testing import TestingDataSet as TDS
from zipline.pipeline.domain import US_EQUITIES
from zipline.testing.fixtures import (
Expand Down Expand Up @@ -81,3 +84,41 @@ def test_latest(self):

expected_col_result = self.expected_latest(column, cal_slice)
assert_frame_equal(col_result, expected_col_result)

@parameterized.expand([
(operator.gt,),
(operator.ge,),
(operator.lt,),
(operator.le,),
])
def test_comparison_errors(self, op):
for column in TDS.columns:
with self.assertRaises(TypeError):
op(column, 1000)
with self.assertRaises(TypeError):
op(1000, column)
with self.assertRaises(TypeError):
op(column, 'test')
with self.assertRaises(TypeError):
op('test', column)

def test_comparison_error_message(self):
column = USEquityPricing.volume
err_msg = (
"'<' not supported between instance of"
" 'int' and 'EquityPricing<US>.volume'."
" Did you mean to use 'EquityPricing<US>.volume.latest'?"
)

with self.assertRaises(TypeError) as e:
column < 1000
self.assertEqual(str(e), err_msg)

with self.assertRaises(TypeError) as e:
1000 < column
self.assertEqual(str(e), err_msg)

try:
column.latest < 1000
except Exception:
self.fail()
26 changes: 26 additions & 0 deletions zipline/pipeline/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ def _static_identity(cls, dataset, name, doc, metadata, *args, **kwargs):
frozenset(sorted(metadata.items(), key=first)),
)

_compare_error_msg = (
"'{op}' not supported between instance of "
"'{other.__class__.__name__}' and '{column.qualname}'. "
"Did you mean use '{column.qualname}.latest'?"
)

def __gt__(self, other):
raise TypeError(
self._compare_error_msg.format(op='>', other=other, column=self)
)

def __ge__(self, other):
raise TypeError(
self._compare_error_msg.format(op='>=', other=other, column=self)
)

def __lt__(self, other):
raise TypeError(
self._compare_error_msg.format(op='<', other=other, column=self)
)

def __le__(self, other):
raise TypeError(
self._compare_error_msg.format(op='<=', other=other, column=self)
)

def specialize(self, domain):
"""Specialize ``self`` to a concrete domain.
"""
Expand Down

0 comments on commit 31c940f

Please sign in to comment.