Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Shorten __repr__ for different assets #1786

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from numpy import full, int32, int64
import pandas as pd
from pandas.util.testing import assert_frame_equal
from six import PY2, viewkeys
from six import viewkeys
import sqlalchemy as sa

from zipline.assets import (
Expand Down Expand Up @@ -379,30 +379,9 @@ def init_class_fixtures(cls):
cls.future = cls.asset_finder.lookup_future_symbol('OMH15')
cls.future2 = cls.asset_finder.lookup_future_symbol('CLG06')

def test_str(self):
strd = str(self.future)
self.assertEqual("Future(2468 [OMH15])", strd)

def test_repr(self):
reprd = repr(self.future)
self.assertIn("Future", reprd)
self.assertIn("2468", reprd)
self.assertIn("OMH15", reprd)
self.assertIn("root_symbol=%s'OM'" % ('u' if PY2 else ''), reprd)
self.assertIn(
"notice_date=Timestamp('2014-01-20 00:00:00+0000', tz='UTC')",
reprd,
)
self.assertIn(
"expiration_date=Timestamp('2014-02-20 00:00:00+0000'",
reprd,
)
self.assertIn(
"auto_close_date=Timestamp('2014-01-18 00:00:00+0000'",
reprd,
)
self.assertIn("tick_size=0.01", reprd)
self.assertIn("multiplier=500", reprd)
self.assertEqual("Future(2468 [OMH15])", reprd)

def test_reduce(self):
assert_equal(
Expand Down
32 changes: 1 addition & 31 deletions zipline/assets/_assets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,12 @@ cdef class Asset:
else:
raise AssertionError('%d is not an operator' % op)

def __str__(self):
def __repr__(self):
if self.symbol:
return '%s(%d [%s])' % (type(self).__name__, self.sid, self.symbol)
else:
return '%s(%d)' % (type(self).__name__, self.sid)

def __repr__(self):
attrs = ('symbol', 'asset_name', 'exchange',
'start_date', 'end_date', 'first_traded', 'auto_close_date')
tuples = ((attr, repr(getattr(self, attr, None)))
for attr in attrs)
strings = ('%s=%s' % (t[0], t[1]) for t in tuples)
params = ', '.join(strings)
return 'Asset(%d, %s)' % (self.sid, params)

cpdef __reduce__(self):
"""
Function used by pickle to determine how to serialize/deserialize this
Expand Down Expand Up @@ -233,16 +224,6 @@ cdef class Asset:

cdef class Equity(Asset):

def __repr__(self):
attrs = ('symbol', 'asset_name', 'exchange',
'start_date', 'end_date', 'first_traded', 'auto_close_date',
'exchange_full')
tuples = ((attr, repr(getattr(self, attr, None)))
for attr in attrs)
strings = ('%s=%s' % (t[0], t[1]) for t in tuples)
params = ', '.join(strings)
return 'Equity(%d, %s)' % (self.sid, params)

property security_start_date:
"""
DEPRECATION: This property should be deprecated and is only present for
Expand Down Expand Up @@ -343,17 +324,6 @@ cdef class Future(Asset):
else:
self.auto_close_date = min(notice_date, expiration_date)

def __repr__(self):
attrs = ('symbol', 'root_symbol', 'asset_name', 'exchange',
'start_date', 'end_date', 'first_traded', 'notice_date',
'expiration_date', 'auto_close_date', 'tick_size',
'multiplier', 'exchange_full')
tuples = ((attr, repr(getattr(self, attr, None)))
for attr in attrs)
strings = ('%s=%s' % (t[0], t[1]) for t in tuples)
params = ', '.join(strings)
return 'Future(%d, %s)' % (self.sid, params)

cpdef __reduce__(self):
"""
Function used by pickle to determine how to serialize/deserialize this
Expand Down