Skip to content

Commit

Permalink
Merge pull request #1204 from quantopian/tell-me-what-my-choices-were
Browse files Browse the repository at this point in the history
Tell me what my choices were
  • Loading branch information
Scott Sanderson committed May 19, 2016
2 parents 1d16309 + 8e32d49 commit 65de121
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions tests/pipeline/test_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,16 @@ def test_bad_output_access(self):
errmsg, "'SomeFactor' object has no attribute 'not_an_attr'",
)

mo = MultipleOutputs()
with self.assertRaises(AttributeError) as e:
MultipleOutputs().not_an_attr
mo.not_an_attr

errmsg = str(e.exception)
self.assertEqual(
errmsg,
"Instance of MultipleOutputs has no output called 'not_an_attr'.",
expected = (
"Instance of MultipleOutputs has no output named 'not_an_attr'."
" Possible choices are: ('alpha', 'beta')."
)
self.assertEqual(errmsg, expected)

with self.assertRaises(ValueError) as e:
alpha, beta = GenericCustomFactor()
Expand Down
12 changes: 7 additions & 5 deletions zipline/pipeline/factors/factor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
factor.py
"""
from functools import partial, wraps
from functools import wraps
from operator import attrgetter
from numbers import Number

Expand Down Expand Up @@ -1212,8 +1212,11 @@ def __getattr__(self, attribute_name):
return RecarrayField(factor=self, attribute=attribute_name)
else:
raise AttributeError(
'Instance of {factor} has no output called {attr!r}.'.format(
factor=type(self).__name__, attr=attribute_name,
'Instance of {factor} has no output named {attr!r}.'
' Possible choices are: {choices}.'.format(
factor=type(self).__name__,
attr=attribute_name,
choices=self.outputs,
)
)

Expand All @@ -1224,8 +1227,7 @@ def __iter__(self):
factor=type(self).__name__,
)
)
RecarrayField_ = partial(RecarrayField, self)
return iter(map(RecarrayField_, self.outputs))
return (RecarrayField(self, attr) for attr in self.outputs)


class RecarrayField(SingleInputMixin, Factor):
Expand Down

0 comments on commit 65de121

Please sign in to comment.