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

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

            # 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,
                dt, "minute", spot_value=result
            )

    def _get_daily_spot_value(self, asset, column, dt):
        reader = self._get_pricing_reader('daily')
        if column == "last_traded":
            last_traded_dt = reader.get_last_traded_dt(asset, dt)

            if isnull(last_traded_dt):
                return pd.NaT
            else:
                return last_traded_dt

Review comment (refactor):
This logic is duplicated here and in the `not ffill` branch. Could we convert this into a function call or dict lookup?

Code after:
                    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,
            dt, "minute", spot_value=result
        )

    def _get_daily_spot_value(self, asset, column, dt):
        reader = self._get_pricing_reader('daily')
        if column == "last_traded":
            last_traded_dt = reader.get_last_traded_dt(asset, dt)

            if isnull(last_traded_dt):
                return pd.NaT
            else:
                return last_traded_dt
        elif column in OHLCV_FIELDS:
            # don't forward fill
            try:
                return reader.get_value(asset, dt, column)
            except NoDataOnDate: