STY: Renames serialization_utils dump and load methods

This commit is contained in:
jfkirk
2015-09-09 10:06:14 -04:00
parent 262f0b7d09
commit 65a4c4523e
3 changed files with 18 additions and 18 deletions
+9 -9
View File
@@ -45,7 +45,7 @@ from zipline.finance.commission import PerShare, PerTrade, PerDollar
from zipline.finance.trading import TradingEnvironment
from zipline.utils.factory import create_random_simulation_parameters
from zipline.utils.serialization_utils import (
load_with_persistent_ids, dump_with_persistent_ids
loads_with_persistent_ids, dumps_with_persistent_ids
)
import zipline.protocol as zp
from zipline.protocol import Event, DATASOURCE_TYPE
@@ -246,9 +246,9 @@ def check_perf_tracker_serialization(perf_tracker):
'total_days',
]
p_string = dump_with_persistent_ids(perf_tracker)
p_string = dumps_with_persistent_ids(perf_tracker)
test = load_with_persistent_ids(p_string, env=perf_tracker.env)
test = loads_with_persistent_ids(p_string, env=perf_tracker.env)
for k in scalar_keys:
nt.assert_equal(getattr(test, k), getattr(perf_tracker, k), k)
@@ -2136,9 +2136,9 @@ class TestPosition(unittest.TestCase):
pos = perf.Position(10, amount=np.float64(120.0), last_sale_date=dt,
last_sale_price=3.4)
p_string = dump_with_persistent_ids(pos)
p_string = dumps_with_persistent_ids(pos)
test = load_with_persistent_ids(p_string, env=None)
test = loads_with_persistent_ids(p_string, env=None)
nt.assert_dict_equal(test.__dict__, pos.__dict__)
@@ -2242,8 +2242,8 @@ class TestPositionTracker(unittest.TestCase):
last_sale_date=dt, last_sale_price=3.4)
pt.update_positions({1: pos1, 3: pos3})
p_string = dump_with_persistent_ids(pt)
test = load_with_persistent_ids(p_string, env=self.env)
p_string = dumps_with_persistent_ids(pt)
test = loads_with_persistent_ids(p_string, env=self.env)
nt.assert_dict_equal(test._position_amounts, pt._position_amounts)
nt.assert_dict_equal(test._position_last_sale_prices,
pt._position_last_sale_prices)
@@ -2261,8 +2261,8 @@ class TestPerformancePeriod(unittest.TestCase):
pp = perf.PerformancePeriod(100, env.asset_finder)
pp.position_tracker = pt
p_string = dump_with_persistent_ids(pp)
test = load_with_persistent_ids(p_string, env=env)
p_string = dumps_with_persistent_ids(pp)
test = loads_with_persistent_ids(p_string, env=env)
correct = pp.__dict__.copy()
del correct['_position_tracker']
+3 -3
View File
@@ -14,7 +14,7 @@
# limitations under the License.
from zipline.utils.serialization_utils import (
load_with_persistent_ids, dump_with_persistent_ids
loads_with_persistent_ids, dumps_with_persistent_ids
)
from nose_parameterized import parameterized
@@ -40,9 +40,9 @@ class PickleSerializationTestCase(TestCase):
obj = cls(*initargs)
for k, v in di_vars.items():
setattr(obj, k, v)
state = dump_with_persistent_ids(obj)
state = dumps_with_persistent_ids(obj)
obj2 = load_with_persistent_ids(state, env=cases_env)
obj2 = loads_with_persistent_ids(state, env=cases_env)
for k, v in di_vars.items():
setattr(obj2, k, v)
+6 -6
View File
@@ -40,9 +40,9 @@ def _persistent_load(persid, env):
return env
def dump_with_persistent_ids(obj, protocol=None):
def dumps_with_persistent_ids(obj, protocol=None):
"""
Performs a pickle dump on the given object, substituting all references to
Performs a pickle dumps on the given object, substituting all references to
a TradingEnvironment or AssetFinder with tokenized representations.
All arguments are passed to pickle.Pickler and are described therein.
@@ -54,21 +54,21 @@ def dump_with_persistent_ids(obj, protocol=None):
return file.getvalue()
def load_with_persistent_ids(str, env):
def loads_with_persistent_ids(str, env):
"""
Performs a pickle load on the given string, substituting the given
Performs a pickle loads on the given string, substituting the given
TradingEnvironment in to any tokenized representations of a
TradingEnvironment or AssetFinder.
Parameters
__________
----------
str : String
The string representation of the object to be unpickled.
env : TradingEnvironment
The TradingEnvironment to be inserted to the unpickled object.
Returns
_______
-------
obj
An unpickled object formed from the parameter 'str'.
"""