コード例 #1
0
 def consume_metadata(self, metadata):
     """
     Consumes the provided metadata in to the metadata cache. The
     existing values in the cache will be overwritten when there
     is a conflict.
     :param metadata: The metadata to be consumed
     """
     # Handle dicts
     if isinstance(metadata, dict):
         self._insert_metadata_dict(metadata)
     # Handle DataFrames
     elif isinstance(metadata, pd.DataFrame):
         self._insert_metadata_dataframe(metadata)
     # Handle readables
     elif hasattr(metadata, 'read'):
         self._insert_metadata_readable(metadata)
     else:
         raise ConsumeAssetMetaDataError(obj=metadata)
コード例 #2
0
 def _insert_metadata_readable(self, readable):
     for row in readable.read():
         # Parse out the row of the readable object
         metadata_dict = {}
         for field in ASSET_FIELDS:
             try:
                 row_value = row[field]
                 # Avoid passing placeholders
                 if row_value and (row_value is not 'None'):
                     metadata_dict[field] = row[field]
             except KeyError:
                 continue
             except IndexError:
                 continue
         # Locate the identifier, fail if not found
         if 'sid' in metadata_dict:
             identifier = metadata_dict['sid']
         elif 'symbol' in metadata_dict:
             identifier = metadata_dict['symbol']
         else:
             raise ConsumeAssetMetaDataError(obj=row)
         self.insert_metadata(identifier, **metadata_dict)