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

Code before:
                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

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

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

Review comment (suggestion):
Since the body of all of these checks is the same, could we coalesce all the conditionals here into something like:

```
    is_valid = (
        (column != 'volume' and not pd.isnull(result)) or
        (result == 0)
    )
    if is_valid:
        return result
```

Better yet, since we don't support `ffill` for non-price fields, could this just be:

```python
assert column == 'price'  # might be 'close'?
if not pd.isnull(result):
    return result
```

Code after:
                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

        # the value we found came from a different day, so we have to
        # adjust the data if there are any adjustments on that day barrier
        return self.get_adjusted_value(
            asset, column, query_dt,