Repository: quantopian/zipline
File: tests/pipeline/test_blaze.py (Python)

Code before:
    def test_empty_checkpoints_macro(self):
        empty_checkpoints = pd.DataFrame({
            'value': [],
            'asof_date': [],
            'timestamp': [],
        })

        self._test_checkpoints_macro(empty_checkpoints)

    def test_checkpoints_out_of_bounds_macro(self):
        # provide two checkpoints, one before the data in the base table
        # and one after, these should not affect the value on the third
        asof_dates = pd.to_datetime(['2013-12-30', '2014-01-04'])
        out_of_bounds = pd.DataFrame({
            'value': [-2, 2],
            'asof_date': asof_dates,
            'timestamp': asof_dates + pd.Timedelta(hours=23),
        })

        # Add a single checkpoint on the query day with a timestamp of exactly
        # the data query time. This should not get pulled to overwrite the
        # expected data on the 3rd.
        exact_query_time = pd.DataFrame({
            'value': [1],
            'asof_date': [pd.Timestamp('2014-01-02')],
            'timestamp': [pd.Timestamp('2014-01-03')],
        })

        self._test_checkpoints_macro(
            pd.concat([out_of_bounds, exact_query_time]),
        )

    def _test_checkpoints(self, checkpoints, ffilled_values=None):
        """Simple checkpoints test that accepts a checkpoints dataframe and
        the expected value for 2014-01-03.

        The underlying data has value -(sid + 1) on 2014-01-01 and sid + 1 on
        2014-01-04.

        Parameters
        ----------
        checkpoints : pd.DataFrame
            The checkpoints data.
        ffilled_value : float, optional
            The value to be read on the third, if not provided, it will be the
            value in the base data that will be naturally ffilled there.
        """
        nassets = len(simple_asset_info)

        dates = pd.to_datetime(['2013-12-31', '2014-01-04'])


Review comment (suggestion):
It's not clear to me how these values are connected to the description in the comment above. What's enforcing that this is the leading data query cutoff time of the query we're going to make? Are these just the values that `test_checkpoints_*` uses by default? If so, it might help clarify to lift this value to a global constant that's shared with `test_checkpoints_*`

Code after:
            ),
        })

        self._test_checkpoints_macro(checkpoints, ffilled_value)

    def test_empty_checkpoints_macro(self):
        empty_checkpoints = pd.DataFrame({
            'value': [],
            'asof_date': [],
            'timestamp': [],
        })

        self._test_checkpoints_macro(empty_checkpoints)

    def test_checkpoints_out_of_bounds_macro(self):
        # provide two checkpoints, one before the data in the base table
        # and one after, these should not affect the value on the third
        asof_dates = self.test_checkpoints_dates[[0, -1]]
        out_of_bounds = pd.DataFrame({
            'value': [-2, 2],
            'asof_date': asof_dates,
            'timestamp': asof_dates + pd.Timedelta(hours=23),
        })

        # Add a single checkpoint on the query day with a timestamp of exactly
        # the data query time. This should not get pulled to overwrite the
        # expected data on the 3rd.
        exact_query_time = pd.DataFrame({
            'value': [1],
            'asof_date': [
                self.test_checkpoints_expected_view_date -
                pd.Timedelta(days=1)
            ],
            'timestamp': [self.test_checkpoints_expected_view_date],
        })

        self._test_checkpoints_macro(
            pd.concat([out_of_bounds, exact_query_time]),
        )

    def _test_checkpoints(self, checkpoints, ffilled_values=None):
        """Simple checkpoints test that accepts a checkpoints dataframe and
        the expected value for 2014-01-03.

        The underlying data has value -(sid + 1) on 2014-01-01 and sid + 1 on
        2014-01-04.

        Parameters
        ----------
        checkpoints : pd.DataFrame
            The checkpoints data.