title: AttributeError: 'generator' object has no attribute 'reindex'
body: <p>I'm building an event-driven, back-testing module, using Quant Start's <a href="http://www.quantstart.com/articles/Event-Driven-Backtesting-with-Python-Part-III" rel="nofollow">tutorial</a> as a rough guideline, and am coming up with an interesting error.</p>
  
  <p>My error occurs at the end of self._convert_csv_files()</p>
  
  <p>I'm trying to reindex each dataframe in self.symbol_data to reflect the union of each dataframe's index, creating a generator object in the process.</p>
  
  <p>The following code is my class:</p>
  
  <pre><code>class HistoricCSVDataHandler(DataHandler):
      """
      HistoricCSVDataHandler is designed to read CSV files for each requested
      symbol from a disk and provide an interface to obtain the "latest" bar in a
      manner identical to a live trading interface.
      """
  
      def __init__(self, events, csv_dir, symbol_list, start_date, end_date):
          """
          Initialises the historic data handler by requesting the location of the
          CSV files and a list of symbols.
  
          It would be assumed that all files are of the form 'symbol.csv,' where
          symbol is a string in the list.
  
          Parameters:
          events - The Event queue.
          csv_dir - Absolute directory path to the csv files.
          symbol_list - A list of symbol strings.
          start_date - A datetime to which we will set the start of the bar index
          end_date - A datetime to which we will set the end of the bar index
          """
  
          self.events = events
          self.csv_dir = csv_dir
          self.symbol_list = symbol_list
          self.bar_index = pd.bdate_range(start_date, end_date)
  
          self.symbol_data = {}
          self.latest_symbol_data = {}
          self.calls = {}
          self.puts = {}
  
          self.continue_backtest= True
  
          self._open_convert_csv_files()
  
      def _open_convert_csv_files(self):
          """
          Opens the CSV files from the data directory, converting them into
          pandas DataFrames within a symbol dictionary.
  
          For this handler it will be assumed that the date is taken from DTN
          IQFeed.  Thus, its format will be respected.
          """
  
          comb_index = None
  
          for s in self.symbol_list:
              # print "Parsing: %s" % s
              # Load the CSV file with no header information, indexed on date
              self.symbol_data[s] = pd.io.parsers.read_csv(
                                      os.path.join(self.csv_dir,'%s.csv' % s),
                                      header=0, index_col=0,
                                      names=['open',
                                             'high',
                                             'low',
                                             'close',
                                             'volume',
                                             'adj close'
                                            ],
                                      parse_dates=True
                                      ).sort()
  
              # Combine the index and pad forward values
              if comb_index is None:
                  comb_index = self.symbol_data[s].index
              else:
                  comb_index = comb_index.union(self.symbol_data[s].index)
  
              #  Set the latest sybmol_data to None
              self.latest_symbol_data[s] = []
  
          self.bar_index = self.bar_index.intersection(comb_index)
  
          self.calls, self.puts = trades.parse_trades()
  
          # Reindex the DataFrames
          for s in self.symbol_list:
              #   print "Reindexing: %s" % s
              self.symbol_data[s] = self.symbol_data[s].reindex(
                                      index=bar_index, method='pad'
                                      ).iterrows()
  </code></pre>
  
  <p>The following is my traceback after %paste:</p>
  
  <pre><code>In [1]: %paste
  # backtest.py
  import dateutil.rrule as dr
  import dateutil.parser as dp
  import dateutil.relativedelta as drel
  import pandas as pd
  import csv
  import Queue
  import datetime
  import cg
  
  # Import Backtesting Classes
  from event import MarketEvent, SignalEvent, OrderEvent, FillEvent
  from data import HistoricCSVDataHandler
  
  # Set input file
  csv_symbol_list = "symbols.csv"
  # Create symbol list
  symbols = []
  symbols_with_currency = []
  symbols_with_currency = cg.create_symbols_list(csv_symbol_list)
  for i in symbols_with_currency:
      symbols.append(i[0])
  
  # Amount of total portfolio reserved for cash
  percent_cash = 0.30
  
  # Declare parameters
  events = Queue.Queue()
  path = "/Users/XXX/Documents/repos/cg2/data"
  start_date = datetime.datetime(2010,12,1)
  end_date = datetime.datetime(2013,12,31)
  
  # Declare the components with respective parameters
  bars = HistoricCSVDataHandler(events, path, symbols, start_date, end_date)
  
  ## -- End pasted text --
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-1-4859f3953713&gt; in &lt;module&gt;()
       35 
       36 # Declare the components with respective parameters
  ---&gt; 37 bars = HistoricCSVDataHandler(events, path, symbols, start_date, end_date)
  
  /Users/XXX/Documents/repos/cg2/data.py in __init__(self, events, csv_dir, symbol_list, start_date, end_date)
       81         self.continue_backtest= True
       82 
  ---&gt; 83         self._open_convert_csv_files()
       84 
       85     def _open_convert_csv_files(self):
  
  /Users/XXX/Documents/repos/cg2/data.py in _open_convert_csv_files(self)
      126         for s in self.symbol_list:
      127             #   print "Reindexing: %s" % s
  --&gt; 128             self.symbol_data[s] = self.symbol_data[s].reindex(
      129                                     index=self.bar_index, method='pad'
      130                                     ).iterrows()
  
  AttributeError: 'generator' object has no attribute 'reindex'
  </code></pre>
  
  <p>If I comment out the troubled for statement:</p>
  
  <pre><code>''' 
          # Reindex the DataFrames
          for s in self.symbol_list:
              #   print "Reindexing: %s" % s
              self.symbol_data[s] = self.symbol_data[s].reindex(
                                      index=self.bar_index, method='pad'
                                      ).iterrows()
          '''
  </code></pre>
  
  <p>I can examine the types of each component used:</p>
  
  <pre><code>In [5]: type(bars.symbol_list)
  Out[5]: list
  
  In [6]: type(bars.symbol_data['A'])
  Out[6]: pandas.core.frame.DataFrame
  
  In [7]: type(bars.bar_index)
  Out[7]: pandas.tseries.index.DatetimeIndex
  
  In [8]: type(bars.symbol_data['A'].index)
  Out[8]: pandas.tseries.index.DatetimeIndex
  </code></pre>