Repository: quantopian/zipline
File: zipline/data/data_portal.py (Python)

Code before:
            if self._is_extra_source(asset, field,
                                     self._augmented_sources_map):
                spot_value = self.get_spot_value(asset, field, perspective_dt,
                                                 data_frequency)
            else:
                spot_value = self.get_spot_value(asset, field, dt,
                                                 data_frequency)

        if isinstance(asset, Equity):
            ratio = self.get_adjustments(asset, field, dt, perspective_dt)[0]
            spot_value *= ratio

        return spot_value

    def _get_minute_spot_value(self, asset, column, dt, ffill=False):
        reader = self._get_pricing_reader('minute')

        if not ffill:
            try:
                return reader.get_value(asset.sid, dt, column)
            except NoDataOnDate:
                if column != 'volume':
                    return np.nan
                else:
                    return 0
        else:
            try:
                # Optimize the best case scenario of a liquid asset
                # returning a valid price.
                result = reader.get_value(asset.sid, dt, column)
                if column != 'volume':
                    if not pd.isnull(result):
                        return result
                else:
                    if result != 0:
                        return result
            except NoDataOnDate:
                # Handling of no data for the desired date is done by the
                # forward filling logic.
                # The last trade may occur on a previous day.
                pass
            # If forward filling, we want the last minute with values (up to
            # and including dt).
            query_dt = reader.get_last_traded_dt(asset, dt)

            if pd.isnull(query_dt):
                # no last traded dt, bail
                if column != 'volume':
                    return np.nan
                else:
                    return 0

Review comment (suggestion):
I don't think this needs to be nested in an `else:` block. Every path out of the `not ffill` block returns a value.

Code after:
            if self._is_extra_source(asset, field,
                                     self._augmented_sources_map):
                spot_value = self.get_spot_value(asset, field, perspective_dt,
                                                 data_frequency)
            else:
                spot_value = self.get_spot_value(asset, field, dt,
                                                 data_frequency)

        if isinstance(asset, Equity):
            ratio = self.get_adjustments(asset, field, dt, perspective_dt)[0]
            spot_value *= ratio

        return spot_value

    def _get_minute_spot_value(self, asset, column, dt, ffill=False):
        reader = self._get_pricing_reader('minute')

        if not ffill:
            try:
                return reader.get_value(asset.sid, dt, column)
            except NoDataOnDate:
                if column != 'volume':
                    return np.nan
                else:
                    return 0

        # At this point the pairing of column='close' and ffill=True is
        # assumed.
        try:
            # Optimize the best case scenario of a liquid asset
            # returning a valid price.
            result = reader.get_value(asset.sid, dt, column)
            if not pd.isnull(result):
                return result
        except NoDataOnDate:
            # Handling of no data for the desired date is done by the
            # forward filling logic.
            # The last trade may occur on a previous day.
            pass
        # If forward filling, we want the last minute with values (up to
        # and including dt).
        query_dt = reader.get_last_traded_dt(asset, dt)

        if pd.isnull(query_dt):
            # no last traded dt, bail
            return np.nan

        result = reader.get_value(asset.sid, query_dt, column)

        if (dt == query_dt) or (dt.date() == query_dt.date()):
            return result