mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
ENH: Added versioning logic to objects.
In order to be able to load from saved state generated by old code, we need to have a notion of the version of the saved state.
This commit is contained in:
@@ -71,7 +71,10 @@ from zipline.finance import trading
|
||||
from . period import PerformancePeriod
|
||||
|
||||
from zipline.finance.trading import with_environment
|
||||
from zipline.utils.serialization_utils import SerializeableZiplineObject
|
||||
from zipline.utils.serialization_utils import (
|
||||
SerializeableZiplineObject,
|
||||
VERSION_LABEL
|
||||
)
|
||||
|
||||
log = logbook.Logger('Performance')
|
||||
|
||||
@@ -493,9 +496,19 @@ class PerformanceTracker(SerializeableZiplineObject):
|
||||
|
||||
state_dict['_dividend_count'] = self._dividend_count
|
||||
|
||||
STATE_VERSION = 1
|
||||
state_dict[VERSION_LABEL] = STATE_VERSION
|
||||
|
||||
return state_dict
|
||||
|
||||
def __setstate__(self, state):
|
||||
|
||||
OLDEST_SUPPORTED_STATE = 1
|
||||
version = state.pop(VERSION_LABEL)
|
||||
|
||||
if version < OLDEST_SUPPORTED_STATE:
|
||||
raise BaseException("PerformanceTracker saved state is too old.")
|
||||
|
||||
super(PerformanceTracker, self).__setstate__(state)
|
||||
|
||||
# Handle the dividend frame specially
|
||||
|
||||
Reference in New Issue
Block a user