From 050fda1bdb8146896961ce2f5276bba128700d4e Mon Sep 17 00:00:00 2001 From: Cam Sweeney Date: Thu, 11 Jan 2018 10:34:16 -0800 Subject: [PATCH] MAINT: Convert dictionary .values() to list for python3 --- catalyst/data/dispatch_bar_reader.py | 4 ++-- catalyst/examples/dual_moving_average.py | 2 +- catalyst/examples/mean_reversion_simple.py | 2 +- catalyst/examples/mean_reversion_simple_custom_fees.py | 2 +- catalyst/examples/rsi_profit_target.py | 2 +- catalyst/examples/simple_loop.py | 2 +- catalyst/examples/simple_universe.py | 2 +- catalyst/exchange/utils/stats_utils.py | 2 +- catalyst/pipeline/graph.py | 4 ++-- catalyst/sources/test_source.py | 4 ++-- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/catalyst/data/dispatch_bar_reader.py b/catalyst/data/dispatch_bar_reader.py index a8e7429b..1b57c463 100644 --- a/catalyst/data/dispatch_bar_reader.py +++ b/catalyst/data/dispatch_bar_reader.py @@ -88,11 +88,11 @@ class AssetDispatchBarReader(with_metaclass(ABCMeta)): if self._last_available_dt is not None: return self._last_available_dt else: - return min(r.last_available_dt for r in self._readers.values()) + return min(r.last_available_dt for r in list(self._readers.values())) @lazyval def first_trading_day(self): - return max(r.first_trading_day for r in self._readers.values()) + return max(r.first_trading_day for r in list(self._readers.values())) def get_value(self, sid, dt, field): asset = self._asset_finder.retrieve_asset(sid) diff --git a/catalyst/examples/dual_moving_average.py b/catalyst/examples/dual_moving_average.py index 3a0a3f1f..d0e6f057 100644 --- a/catalyst/examples/dual_moving_average.py +++ b/catalyst/examples/dual_moving_average.py @@ -84,7 +84,7 @@ def handle_data(context, data): def analyze(context, perf): # Get the base_currency that was passed as a parameter to the simulation - base_currency = context.exchanges.values()[0].base_currency.upper() + base_currency = list(context.exchanges.values())[0].base_currency.upper() # First chart: Plot portfolio value using base_currency ax1 = plt.subplot(411) diff --git a/catalyst/examples/mean_reversion_simple.py b/catalyst/examples/mean_reversion_simple.py index 4178e0f8..bec9c327 100644 --- a/catalyst/examples/mean_reversion_simple.py +++ b/catalyst/examples/mean_reversion_simple.py @@ -161,7 +161,7 @@ def analyze(context=None, perf=None): import matplotlib.pyplot as plt # The base currency of the algo exchange - base_currency = context.exchanges.values()[0].base_currency.upper() + base_currency = list(context.exchanges.values())[0].base_currency.upper() # Plot the portfolio value over time. ax1 = plt.subplot(611) diff --git a/catalyst/examples/mean_reversion_simple_custom_fees.py b/catalyst/examples/mean_reversion_simple_custom_fees.py index fc44c93e..3d323e38 100644 --- a/catalyst/examples/mean_reversion_simple_custom_fees.py +++ b/catalyst/examples/mean_reversion_simple_custom_fees.py @@ -161,7 +161,7 @@ def analyze(context=None, perf=None): import matplotlib.pyplot as plt # The base currency of the algo exchange - base_currency = context.exchanges.values()[0].base_currency.upper() + base_currency = list(context.exchanges.values())[0].base_currency.upper() # Plot the portfolio value over time. ax1 = plt.subplot(611) diff --git a/catalyst/examples/rsi_profit_target.py b/catalyst/examples/rsi_profit_target.py index a07d63f7..1526b035 100644 --- a/catalyst/examples/rsi_profit_target.py +++ b/catalyst/examples/rsi_profit_target.py @@ -175,7 +175,7 @@ def handle_data(context, data): def analyze(context=None, results=None): import matplotlib.pyplot as plt - base_currency = context.exchanges.values()[0].base_currency.upper() + base_currency = list(context.exchanges.values())[0].base_currency.upper() # Plot the portfolio and asset data. ax1 = plt.subplot(611) results.loc[:, 'portfolio_value'].plot(ax=ax1) diff --git a/catalyst/examples/simple_loop.py b/catalyst/examples/simple_loop.py index 1e639264..0de91d3d 100644 --- a/catalyst/examples/simple_loop.py +++ b/catalyst/examples/simple_loop.py @@ -57,7 +57,7 @@ def analyze(context, perf): log.info('the stats: {}'.format(get_pretty_stats(perf))) # The base currency of the algo exchange - base_currency = context.exchanges.values()[0].base_currency.upper() + base_currency = list(context.exchanges.values())[0].base_currency.upper() # Plot the portfolio value over time. ax1 = plt.subplot(611) diff --git a/catalyst/examples/simple_universe.py b/catalyst/examples/simple_universe.py index e781281f..f19b2e25 100644 --- a/catalyst/examples/simple_universe.py +++ b/catalyst/examples/simple_universe.py @@ -41,7 +41,7 @@ from catalyst.exchange.utils.exchange_utils import get_exchange_symbols def initialize(context): context.i = -1 # minute counter - context.exchange = context.exchanges.values()[0].name.lower() + context.exchange = list(context.exchanges.values())[0].name.lower() context.base_currency = context.exchanges.values()[0].base_currency.lower() diff --git a/catalyst/exchange/utils/stats_utils.py b/catalyst/exchange/utils/stats_utils.py index 82894862..8cc9b6ca 100644 --- a/catalyst/exchange/utils/stats_utils.py +++ b/catalyst/exchange/utils/stats_utils.py @@ -287,7 +287,7 @@ def get_pretty_stats(stats, recorded_cols=None, num_rows=10, show_tail=True): """ if isinstance(stats, pd.DataFrame): - stats = stats.T.to_dict().values() + stats = list(stats.T.to_dict().values()) stats.sort(key=itemgetter('period_close')) if len(stats) > num_rows: diff --git a/catalyst/pipeline/graph.py b/catalyst/pipeline/graph.py index 47e349c1..a4f89d14 100644 --- a/catalyst/pipeline/graph.py +++ b/catalyst/pipeline/graph.py @@ -142,7 +142,7 @@ class TermGraph(object): at the end of execution. """ refcounts = self.graph.out_degree() - for t in self.outputs.values(): + for t in list(self.outputs.values()): refcounts[t] += 1 for t in initial_terms: @@ -238,7 +238,7 @@ class ExecutionPlan(TermGraph): min_extra_rows=0): super(ExecutionPlan, self).__init__(terms) - for term in terms.values(): + for term in list(terms.values()): self.set_extra_rows( term, all_dates, diff --git a/catalyst/sources/test_source.py b/catalyst/sources/test_source.py index 673e2373..f1503428 100644 --- a/catalyst/sources/test_source.py +++ b/catalyst/sources/test_source.py @@ -144,7 +144,7 @@ class SpecificEquityTrades(object): for identifier in self.identifiers: assets_by_identifier[identifier] = env.asset_finder.\ lookup_generic(identifier, datetime.now())[0] - self.sids = [asset.sid for asset in assets_by_identifier.values()] + self.sids = [asset.sid for asset in list(assets_by_identifier.values())] for event in self.event_list: event.sid = assets_by_identifier[event.sid].sid @@ -167,7 +167,7 @@ class SpecificEquityTrades(object): for identifier in self.identifiers: assets_by_identifier[identifier] = env.asset_finder.\ lookup_generic(identifier, datetime.now())[0] - self.sids = [asset.sid for asset in assets_by_identifier.values()] + self.sids = [asset.sid for asset in list(assets_by_identifier.values())] # Hash_value for downstream sorting. self.arg_string = hash_args(*args, **kwargs)