From 60418f931d6cdc6081954f12922c323c4029b2db Mon Sep 17 00:00:00 2001 From: Andrew Daniels Date: Wed, 24 Jun 2015 13:35:51 -0400 Subject: [PATCH] DEV: Refactor logic for populating AssetFinder caches Now populate_cache actually handles the population, and spawn_asset is non-public, i.e. _spawn_asset --- zipline/assets/assets.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/zipline/assets/assets.py b/zipline/assets/assets.py index 7206088e..43967f6f 100644 --- a/zipline/assets/assets.py +++ b/zipline/assets/assets.py @@ -242,12 +242,17 @@ class AssetFinder(object): self.identifier_cache = {} self.fuzzy_match = {} - counter = 0 for identifier, row in self.metadata_cache.items(): - self.spawn_asset(identifier=identifier, **row) - counter += 1 + asset = self._spawn_asset(identifier=identifier, **row) - def spawn_asset(self, identifier, **kwargs): + # Insert asset into the various caches + self.cache[asset.sid] = asset + self.identifier_cache[identifier] = asset + + if asset.symbol is not '': + self.sym_cache.setdefault(asset.symbol, []).append(asset) + + def _spawn_asset(self, identifier, **kwargs): # Check if the sid is declared try: @@ -331,11 +336,6 @@ class AssetFinder(object): else: raise InvalidAssetType(asset_type=asset_type) - self.cache[asset.sid] = asset - self.identifier_cache[identifier] = asset - if asset.symbol is not '': - self.sym_cache.setdefault(asset.symbol, []).append(asset) - return asset @property