'Ensure that `Factor.linear_regression` is consistent with the built-in
factor `RollingLinearRegressionOfReturns`.'

@parameter_space(returns_length=[2, 3], regression_length=[3, 4])
def test_factor_regression_method(self, returns_length, regression_length):

    my_asset = self.asset_finder.retrieve_asset(self.sids[0])
    returns = Returns(window_length=returns_length, inputs=[self.col])
    returns_slice = returns[my_asset]
    regression = returns.linear_regression(target=returns_slice, regression_length=regression_length)
    expected_regression = RollingLinearRegressionOfReturns(target=my_asset, returns_length=returns_length, regression_length=regression_length)
    expected_regression.inputs = [returns, returns_slice]
    columns = {'regression': regression, 'expected_regression': expected_regression}
    results = self.run_pipeline(Pipeline(columns=columns), self.pipeline_start_date, self.pipeline_end_date)
    regression_results = results['regression'].unstack()
    expected_regression_results = results['expected_regression'].unstack()
    assert_frame_equal(regression_results, expected_regression_results)
    class DateFactor(CustomFactor, ):
        window_length = 1
        inputs = []
        dtype = datetime64ns_dtype
        window_safe = True
        def compute(self, today, assets, out):
            pass
    date_factor = DateFactor()
    date_factor_slice = date_factor[my_asset]
    with self.assertRaises(TypeError):
        date_factor.linear_regression(target=returns_slice, regression_length=regression_length)
    with self.assertRaises(TypeError):
        returns.linear_regression(target=date_factor_slice, regression_length=regression_length)
