In this method, for the given sector, we'll get the data we need for each stock
    in the sector from IEX. Once we have the data, we'll check that the earnings
    reports meet our criteria with `eps_good()`. We'll put stocks that meet those
    requirements into a dataframe along with all the data about them we'll need.

def build_sector_fundamentals(sector):
    '''
    In this method, for the given sector, we'll get the data we need for each stock
    in the sector from IEX. Once we have the data, we'll check that the earnings
    reports meet our criteria with `eps_good()`. We'll put stocks that meet those
    requirements into a dataframe along with all the data about them we'll need.
    '''
    stocks = get_sector(sector)
    if len(stocks) == 0:
        raise ValueError("Invalid sector name: {}".format(sector))

    # If we can't see its PE here, we're probably not interested in a stock.
    # Omit it from batch queries.
    stocks = [s for s in stocks if s['peRatio'] is not None]

    # IEX doesn't like batch queries for more than 100 symbols at a time.
    # We need to build our fundamentals info iteratively.
    batch_idx = 0
    batch_size = 99
    fundamentals_dict = {}
    while batch_idx < len(stocks):
        symbol_batch = [s['symbol']
                        for s in stocks[batch_idx:batch_idx + batch_size]]
        stock_batch = Stock(symbol_batch)

        # Pull all the data we'll need from IEX.
        financials_json = stock_batch.get_financials()
        quote_json = stock_batch.get_quote()
        stats_json = stock_batch.get_key_stats()
        earnings_json = stock_batch.get_earnings()

        for symbol in symbol_batch:
            # We'll filter based on earnings first to keep our fundamentals
            # info a bit cleaner.
            if not eps_good(earnings_json[symbol]):
                continue

            # Make sure we have all the data we'll need for our filters for
            # this stock.
            if not data_quality_good(
                    symbol,
                    financials_json,
                    quote_json,
                    stats_json):
                continue

            fundamentals_dict[symbol] = get_fundamental_data_for_symbol(
                symbol,
                financials_json,
                quote_json,
                stats_json
            )

        batch_idx += batch_size
    # Transform all our data into a more filterable form - a dataframe - with
    # a bit of pandas magic.
    return pd.DataFrame.from_dict(fundamentals_dict).T