diff --git a/zipline/finance/blotter.py b/zipline/finance/blotter.py index 0553bbce..11b22d4f 100644 --- a/zipline/finance/blotter.py +++ b/zipline/finance/blotter.py @@ -251,10 +251,6 @@ class Blotter(SerializeableZiplineObject): yield txn, order - def __getinitargs__(self): - # Ensure that init is called on deserialization - return () - def __getstate__(self): state_to_save = ['new_orders', 'orders', '_status'] @@ -272,6 +268,8 @@ class Blotter(SerializeableZiplineObject): def __setstate__(self, state): + self.__init__() + OLDEST_SUPPORTED_STATE = 1 version = state.pop(VERSION_LABEL) diff --git a/zipline/finance/performance/position.py b/zipline/finance/performance/position.py index 9e309683..f8bfb11a 100644 --- a/zipline/finance/performance/position.py +++ b/zipline/finance/performance/position.py @@ -38,6 +38,8 @@ from math import ( floor, ) +from copy import copy + import logbook import zipline.protocol as zp @@ -214,7 +216,7 @@ last_sale_price: {last_sale_price}" def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION diff --git a/zipline/finance/slippage.py b/zipline/finance/slippage.py index 59109c38..da9b6d42 100644 --- a/zipline/finance/slippage.py +++ b/zipline/finance/slippage.py @@ -134,7 +134,7 @@ class Transaction(SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION @@ -271,7 +271,7 @@ class VolumeShareSlippage(SlippageModel, SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION @@ -309,7 +309,7 @@ class FixedSlippage(SlippageModel, SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION diff --git a/zipline/protocol.py b/zipline/protocol.py index 84294dad..8d3e0e46 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from copy import copy + from six import iteritems, iterkeys import pandas as pd import numpy as np @@ -144,7 +146,7 @@ class Portfolio(SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION @@ -196,7 +198,7 @@ class Account(SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION @@ -230,7 +232,7 @@ class Position(SerializeableZiplineObject): def __getstate__(self): - state_dict = self.__dict__ + state_dict = copy(self.__dict__) STATE_VERSION = 1 state_dict[VERSION_LABEL] = STATE_VERSION