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

Code before:

        Returns
        -------
        value : float, int, or pd.Timestamp
            The value of the given ``field`` for ``asset`` at ``dt`` with any
            adjustments known by ``perspective_dt`` applied. The return type is
            based on the ``field`` requested. If the field is one of 'open',
            'high', 'low', 'close', or 'price', the value will be a float. If
            the ``field`` is 'volume' the value will be a int. If the ``field``
            is 'last_traded' the value will be a Timestamp.
        """
        if spot_value is None:
            # if this a fetcher field, we want to use perspective_dt (not dt)
            # because we want the new value as of midnight (fetcher only works
            # on a daily basis, all timestamps are on midnight)
            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):
            if data_frequency == 'daily':
                dt = self.trading_calendar.session_open(dt)

            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 ffill:
            # 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 0
                else:
                    return np.nan
        else:
            # If not forward filling, we just want dt.
            query_dt = dt

        try:

Review comment (bug):
When in `daily` data frequency, I don't believe we should be introducing a dt which is not date normalized.

I think this bug shows that we should be adding a `data_frequency` parameter to `get_adjustments`, and making the query for `get_adjustments` aware of the `data_frequency`.

 

Code after:

        Returns
        -------
        value : float, int, or pd.Timestamp
            The value of the given ``field`` for ``asset`` at ``dt`` with any
            adjustments known by ``perspective_dt`` applied. The return type is
            based on the ``field`` requested. If the field is one of 'open',
            'high', 'low', 'close', or 'price', the value will be a float. If
            the ``field`` is 'volume' the value will be a int. If the ``field``
            is 'last_traded' the value will be a Timestamp.
        """
        if spot_value is None:
            # if this a fetcher field, we want to use perspective_dt (not dt)
            # because we want the new value as of midnight (fetcher only works
            # on a daily basis, all timestamps are on midnight)
            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 ffill:
            # 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 0
                else:
                    return np.nan
        else:
            # If not forward filling, we just want dt.
            query_dt = dt

        try:
            result = reader.get_value(asset.sid, query_dt, column)
        except NoDataOnDate:
            if column == 'volume':