From 1fbc17d2815ee31edd07714329e8c439137d18b9 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 28 Oct 2016 14:05:49 -0400 Subject: [PATCH 1/3] BUG: Raise `SidsNotFound` in retrieve_asset. --- zipline/assets/assets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index e3876f59..ec6198ec 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -364,7 +364,10 @@ class AssetFinder(object): Retrieve the Asset for a given sid. """ try: - return self._asset_cache[sid] + asset = self._asset_cache[sid] + if asset is None and not default_none: + raise SidsNotFound(sids=[sid]) + return asset except KeyError: return self.retrieve_all((sid,), default_none=default_none)[0] From 8ccef7b9abb91c7bfa60d7a2acccc1319251909e Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 28 Oct 2016 14:06:35 -0400 Subject: [PATCH 2/3] DOC: Comment on outdated code. --- zipline/testing/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zipline/testing/core.py b/zipline/testing/core.py index f9832767..24821d93 100644 --- a/zipline/testing/core.py +++ b/zipline/testing/core.py @@ -748,6 +748,9 @@ class FetcherDataPortal(DataPortal): # otherwise just return a fixed value return int(asset) + # XXX: These aren't actually the methods that are used by the superclasses, + # so these don't do anything, and this class will likely produce unexpected + # results for history(). def _get_daily_window_for_sid(self, asset, field, days_in_window, extra_slot=True): return np.arange(days_in_window, dtype=np.float64) From 21a3f1a7ed85b9b9fdf60dab0b568eef50ea3288 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 28 Oct 2016 14:28:59 -0400 Subject: [PATCH 3/3] MAINT: Consolidate data_portal names. Rename _get_daily_window_for_sids to _get_daily_window_data. Rename _get_minute_window_for_assets to _get_minute_window_data. Rename _get_daily_data to get_daily_spot_value. --- zipline/data/data_portal.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/zipline/data/data_portal.py b/zipline/data/data_portal.py index 20f43102..f0b0d446 100644 --- a/zipline/data/data_portal.py +++ b/zipline/data/data_portal.py @@ -454,7 +454,7 @@ class DataPortal(object): return None if data_frequency == "daily": - return self._get_daily_data(asset, field, session_label) + return self._get_daily_spot_value(asset, field, session_label) else: if field == "last_traded": return self.get_last_traded_dt(asset, dt, 'minute') @@ -629,7 +629,7 @@ class DataPortal(object): dt, "minute", spot_value=result ) - def _get_daily_data(self, asset, column, dt): + def _get_daily_spot_value(self, asset, column, dt): reader = self._get_pricing_reader('daily') if column == "last_traded": last_traded_dt = reader.get_last_traded_dt(asset, dt) @@ -703,16 +703,19 @@ class DataPortal(object): columns=assets ) - def _get_history_daily_window_data( - self, assets, days_for_window, end_dt, field_to_use): - ends_at_midnight = end_dt.hour == 0 and end_dt.minute == 0 + def _get_history_daily_window_data(self, + assets, + days_for_window, + end_dt, + field_to_use): + ends_at_midnight = (0 == end_dt.hour == end_dt.minute) if ends_at_midnight: # two cases where we use daily data for the whole range: # 1) the history window ends at midnight utc. # 2) the last desired day of the window is after the # last trading day, use daily data for the whole range. - return self._get_daily_window_for_sids( + return self._get_daily_window_data( assets, field_to_use, days_for_window, @@ -720,7 +723,7 @@ class DataPortal(object): ) else: # minute mode, requesting '1d' - daily_data = self._get_daily_window_for_sids( + daily_data = self._get_daily_window_data( assets, field_to_use, days_for_window[0:-1] @@ -788,7 +791,7 @@ class DataPortal(object): if minutes_for_window[0] < self._first_trading_minute: self._handle_minute_history_out_of_bounds(bar_count) - asset_minute_data = self._get_minute_window_for_assets( + asset_minute_data = self._get_minute_window_data( assets, field_to_use, minutes_for_window, @@ -899,7 +902,7 @@ class DataPortal(object): df.loc[normed_index > asset.end_date, asset] = nan return df - def _get_minute_window_for_assets(self, assets, field, minutes_for_window): + def _get_minute_window_data(self, assets, field, minutes_for_window): """ Internal method that gets a window of adjusted minute data for an asset and specified date range. Used to support the history API method for @@ -909,8 +912,8 @@ class DataPortal(object): Parameters ---------- - asset : Asset - The asset whose data is desired. + assets : iterable[Asset] + The assets whose data is desired. field: string The specific field to return. "open", "high", "close_price", etc. @@ -928,8 +931,11 @@ class DataPortal(object): field, False) - def _get_daily_window_for_sids( - self, assets, field, days_in_window, extra_slot=True): + def _get_daily_window_data(self, + assets, + field, + days_in_window, + extra_slot=True): """ Internal method that gets a window of adjusted daily data for a sid and specified date range. Used to support the history API method for