ENH: Adds security_start_date and _end_date with deprecation warnings

This commit is contained in:
jfkirk
2015-06-16 14:26:05 -04:00
parent 3a88da28ca
commit aa92922ea8
2 changed files with 56 additions and 19 deletions
+22 -3
View File
@@ -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))
+34 -16
View File
@@ -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):