From 54ddd1c10981070ab7c1fa54bdb76fba51fa9108 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Sat, 4 Jan 2014 20:55:43 -0500 Subject: [PATCH] MAINT: print function clean up in preparation for Python 3 - Use `print()` function for all print calls - Fix strip and format calls that were on the outside of the print function for some reason. (Which were breaking in Python 3 because of print returning None.) - Remove commented out print calls. --- tests/test_perf_tracking.py | 1 - tests/test_transforms.py | 4 ++-- zipline/data/loader.py | 8 ++++---- zipline/examples/dual_moving_average.py | 2 +- zipline/examples/olmar.py | 4 ++-- zipline/test_algorithms.py | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index 738c80fa..09388820 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -974,7 +974,6 @@ shares in position" "should have a cost basis of 11.33" ) - # print "second period pnl is {pnl}".format(pnl=pp2.pnl) self.assertEqual(pp.pnl, -800, "this period goes from +400 to -400") pp3 = perf.PerformancePeriod(1000.0) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 5aeed715..43df06d8 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -300,7 +300,7 @@ class TestTALIB(TestCase): and n not in BLACKLIST] for name in names: - print name + print(name) zipline_transform = getattr(ta, name)(sid=0) talib_fn = getattr(talib.abstract, name) @@ -337,7 +337,7 @@ class TestTALIB(TestCase): and np.all(np.isnan(expected_result))): self.assertTrue(np.allclose(zipline_result, expected_result)) else: - print '--- NAN' + print('--- NAN') # reset generator so next iteration has data # self.source, self.panel = \ diff --git a/zipline/data/loader.py b/zipline/data/loader.py index 8e8ed5a8..64333bb3 100644 --- a/zipline/data/loader.py +++ b/zipline/data/loader.py @@ -163,7 +163,7 @@ def load_market_data(bm_symbol='^GSPC'): print(""" data files aren't distributed with source. Fetching data from Yahoo Finance. -""").strip() +""".strip()) dump_benchmarks(bm_symbol) fp_bm = get_datafile(get_benchmark_filename(bm_symbol), "rb") @@ -211,7 +211,7 @@ Fetching data from Yahoo Finance. print(""" data files aren't distributed with source. Fetching data from {0} -""").format(source).strip() +""".format(source).strip()) dump_treasury_curves(module, filename) fp_tr = get_datafile(filename, "rb") @@ -277,7 +277,7 @@ must specify stocks or indexes""" if stocks is not None: for stock in stocks: - print stock + print(stock) cache_filename = "{stock}-{start}-{end}.csv".format( stock=stock, start=start, @@ -292,7 +292,7 @@ must specify stocks or indexes""" if indexes is not None: for name, ticker in indexes.iteritems(): - print name + print(name) stkd = DataReader(ticker, 'yahoo', start, end).sort_index() data[name] = stkd diff --git a/zipline/examples/dual_moving_average.py b/zipline/examples/dual_moving_average.py index 3bb81ef5..e0f643ed 100755 --- a/zipline/examples/dual_moving_average.py +++ b/zipline/examples/dual_moving_average.py @@ -96,5 +96,5 @@ if __name__ == '__main__': plt.legend(loc=0) sharpe = [risk['sharpe'] for risk in dma.risk_report['one_month']] - print "Monthly Sharpe ratios:", sharpe + print("Monthly Sharpe ratios: {0}".format(sharpe)) plt.gcf().set_size_inches(18, 8) diff --git a/zipline/examples/olmar.py b/zipline/examples/olmar.py index 23e9611f..ab9ba1ff 100644 --- a/zipline/examples/olmar.py +++ b/zipline/examples/olmar.py @@ -128,9 +128,9 @@ def simplex_projection(v, b=1): :Example: >>> proj = simplex_projection([.4 ,.3, -.4, .5]) - >>> print proj + >>> print(proj) array([ 0.33333333, 0.23333333, 0. , 0.43333333]) - >>> print proj.sum() + >>> print(proj.sum()) 1.0 Original matlab implementation: John Duchi (jduchi@cs.berkeley.edu) diff --git a/zipline/test_algorithms.py b/zipline/test_algorithms.py index 3500f7b1..e4a05fdd 100644 --- a/zipline/test_algorithms.py +++ b/zipline/test_algorithms.py @@ -340,7 +340,7 @@ class TestTargetValueAlgorithm(TradingAlgorithm): self.target_shares = 10 return else: - print self.portfolio + print(self.portfolio) assert self.portfolio.positions[0]['amount'] == \ self.target_shares, "Orders not filled immediately." assert self.portfolio.positions[0]['last_sale_price'] == \