mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
MAINT: Check attributes instead of contains for event fields.
In support of source that emits a subclass of Event which defines some fields as properties instead of doubling the value in the `Event.__dict__` Use hasattr instead of the overridden __contains__ method of the Event class, so that when non-algorithm facing code checks for field existence, properties count. Intentionally not touching the `__contains__` in Event, to avoid changing, at the moment, any algo behavior that relies on the `__contains__` behavior's use of `__dict__`
This commit is contained in:
@@ -53,8 +53,8 @@ class TestDataFrameSource(TestCase):
|
||||
for event in source:
|
||||
self.assertTrue('sid' in event)
|
||||
self.assertTrue('arbitrary' in event)
|
||||
self.assertTrue('volume' in event)
|
||||
self.assertTrue('price' in event)
|
||||
self.assertTrue(hasattr(event, 'volume'))
|
||||
self.assertTrue(hasattr(event, 'price'))
|
||||
self.assertEquals(event['arbitrary'], 1.)
|
||||
self.assertEquals(event['sid'], 0)
|
||||
self.assertTrue(isinstance(event['volume'], int))
|
||||
|
||||
@@ -96,7 +96,7 @@ class ReturnsFromPriorClose(object):
|
||||
We only allow events with a price field to be run through
|
||||
the returns transform.
|
||||
"""
|
||||
if 'price' not in event:
|
||||
if not hasattr(event, 'price'):
|
||||
raise WrongDataForTransform(
|
||||
transform="ReturnsEventWindow",
|
||||
fields=['price'])
|
||||
|
||||
@@ -280,7 +280,7 @@ class EventWindow(with_metaclass(ABCMeta)):
|
||||
We only allow events with all of our tracked fields.
|
||||
"""
|
||||
# All events require a 'dt' field.
|
||||
if 'dt' not in event:
|
||||
if not hasattr(event, 'dt'):
|
||||
raise WrongDataForTransform(
|
||||
transform=self.__class__.__name__,
|
||||
fields=['dt'],
|
||||
|
||||
Reference in New Issue
Block a user