MCPcopy
hub / github.com/quantopian/zipline / __iter__

Method __iter__

zipline/sources/requests_csv.py:402–455  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

400 return df
401
402 def __iter__(self):
403 asset_cache = {}
404 for dt, series in self.df.iterrows():
405 if dt < self.start_date:
406 continue
407
408 if dt > self.end_date:
409 return
410
411 event = FetcherEvent()
412 # when dt column is converted to be the dataframe's index
413 # the dt column is dropped. So, we need to manually copy
414 # dt into the event.
415 event.dt = dt
416 for k, v in series.iteritems():
417 # convert numpy integer types to
418 # int. This assumes we are on a 64bit
419 # platform that will not lose information
420 # by casting.
421 # TODO: this is only necessary on the
422 # amazon qexec instances. would be good
423 # to figure out how to use the numpy dtypes
424 # without this check and casting.
425 if isinstance(v, numpy.integer):
426 v = int(v)
427
428 setattr(event, k, v)
429
430 # If it has start_date, then it's already an Asset
431 # object from asset_for_symbol, and we don't have to
432 # transform it any further. Checking for start_date is
433 # faster than isinstance.
434 if event.sid in asset_cache:
435 event.sid = asset_cache[event.sid]
436 elif hasattr(event.sid, 'start_date'):
437 # Clone for user algo code, if we haven't already.
438 asset_cache[event.sid] = event.sid
439 elif self.finder and isinstance(event.sid, int):
440 asset = self.finder.retrieve_asset(event.sid,
441 default_none=True)
442 if asset:
443 # Clone for user algo code.
444 event.sid = asset_cache[asset] = asset
445 elif self.mask:
446 # When masking drop all non-mappable values.
447 continue
448 elif self.symbol is None:
449 # If the event's sid property is an int we coerce
450 # it into an Equity.
451 event.sid = asset_cache[event.sid] = Equity(event.sid)
452
453 event.type = DATASOURCE_TYPE.CUSTOM
454 event.source_id = self.namestring
455 yield event
456
457
458class PandasRequestsCSV(PandasCSV):

Callers

nothing calls this directly

Calls 2

FetcherEventClass · 0.85
retrieve_assetMethod · 0.80

Tested by

no test coverage detected