From 65a4c4523e03ea1b2ee5a13b554162ff7de72255 Mon Sep 17 00:00:00 2001 From: jfkirk Date: Wed, 9 Sep 2015 10:06:14 -0400 Subject: [PATCH] STY: Renames serialization_utils dump and load methods --- tests/test_perf_tracking.py | 18 +++++++++--------- tests/test_pickle_serialization.py | 6 +++--- zipline/utils/serialization_utils.py | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index 8f5fad91..2b144e48 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -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'] diff --git a/tests/test_pickle_serialization.py b/tests/test_pickle_serialization.py index 4ef4e1a3..f5c9fc23 100644 --- a/tests/test_pickle_serialization.py +++ b/tests/test_pickle_serialization.py @@ -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) diff --git a/zipline/utils/serialization_utils.py b/zipline/utils/serialization_utils.py index b1a7a7dd..9532c155 100644 --- a/zipline/utils/serialization_utils.py +++ b/zipline/utils/serialization_utils.py @@ -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'. """