From aa92922ea88cefd8bba2469dc3f52ea33d54e360 Mon Sep 17 00:00:00 2001 From: jfkirk Date: Tue, 16 Jun 2015 14:26:05 -0400 Subject: [PATCH] ENH: Adds security_start_date and _end_date with deprecation warnings --- tests/test_assets.py | 25 ++++++++++++++++--- zipline/assets/_assets.pyx | 50 ++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/tests/test_assets.py b/tests/test_assets.py index 07597bdd..8f4786e1 100644 --- a/tests/test_assets.py +++ b/tests/test_assets.py @@ -28,7 +28,7 @@ import pickle import pprint import pytz import uuid - +import warnings import pandas as pd from nose_parameterized import parameterized @@ -223,9 +223,9 @@ class AssetTestCase(TestCase): attrs_to_check = ['end_date', 'exchange', 'first_traded', - 'asset_end_date', + 'end_date', 'asset_name', - 'asset_start_date', + 'start_date', 'sid', 'start_date', 'symbol'] @@ -610,3 +610,22 @@ class AssetFinderTestCase(TestCase): # Build a finder that is not allowed to assign sids, asserting failure with self.assertRaises(SidAssignmentError): AssetFinder(metadata=metadata, allow_sid_assignment=False) + + def test_security_dates_warning(self): + + # Build an asset with an end_date + eq_end = pd.Timestamp('2012-01-01', tz='UTC') + equity_asset = Equity(1, symbol="TESTEQ", end_date=eq_end) + + # Catch all warnings + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered + warnings.simplefilter("always") + equity_asset.security_start_date + equity_asset.security_end_date + equity_asset.security_name + # Verify the warning + self.assertEqual(3, len(w)) + for warning in w: + self.assertTrue(issubclass(warning.category, + DeprecationWarning)) diff --git a/zipline/assets/_assets.pyx b/zipline/assets/_assets.pyx index 89d6761b..f0d4032e 100644 --- a/zipline/assets/_assets.pyx +++ b/zipline/assets/_assets.pyx @@ -19,6 +19,7 @@ Cythonized Asset object. cimport cython import numpy as np +import warnings cimport numpy as np # IMPORTANT NOTE: You must change this template if you change @@ -67,22 +68,6 @@ cdef class Asset: def __hash__(self): return self.sid_hash - property asset_start_date: - """ - Alias for start_date to disambiguate from other `start_date`s in the - system. - """ - def __get__(self): - return self.start_date - - property asset_end_date: - """ - Alias for end_date to disambiguate from other `end_date`s in the - system. - """ - def __get__(self): - return self.end_date - def __richcmp__(x, y, int op): """ Cython rich comparison method. This is used in place of various @@ -203,6 +188,39 @@ cdef class Equity(Asset): 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 + backwards compatibility + """ + def __get__(self): + warnings.warn("The security_start_date property will soon be " + "retired. Please use the start_date property instead.", + DeprecationWarning) + return self.start_date + + property security_end_date: + """ + DEPRECATION: This property should be deprecated and is only present for + backwards compatibility + """ + def __get__(self): + warnings.warn("The security_end_date property will soon be " + "retired. Please use the end_date property instead.", + DeprecationWarning) + return self.end_date + + property security_name: + """ + DEPRECATION: This property should be deprecated and is only present for + backwards compatibility + """ + def __get__(self): + warnings.warn("The security_name property will soon be " + "retired. Please use the asset_name property instead.", + DeprecationWarning) + return self.asset_name + cdef class Future(Asset):