'Ensure that `Factor.pearsonr` and `Factor.spearmanr` are consistent
with the built-in factors `RollingPearsonOfReturns` and
`RollingSpearmanOfReturns`.'

@parameter_space(returns_length=[2, 3], correlation_length=[3, 4])
def test_factor_correlation_methods(self, returns_length, correlation_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]
    pearson = returns.pearsonr(target=returns_slice, correlation_length=correlation_length)
    spearman = returns.spearmanr(target=returns_slice, correlation_length=correlation_length)
    expected_pearson = RollingPearsonOfReturns(target=my_asset, returns_length=returns_length, correlation_length=correlation_length)
    expected_spearman = RollingSpearmanOfReturns(target=my_asset, returns_length=returns_length, correlation_length=correlation_length)
    expected_pearson.inputs = [returns, returns_slice]
    expected_spearman.inputs = [returns, returns_slice]
    columns = {'pearson': pearson, 'spearman': spearman, 'expected_pearson': expected_pearson, 'expected_spearman': expected_spearman}
    results = self.run_pipeline(Pipeline(columns=columns), self.pipeline_start_date, self.pipeline_end_date)
    pearson_results = results['pearson'].unstack()
    spearman_results = results['spearman'].unstack()
    expected_pearson_results = results['expected_pearson'].unstack()
    expected_spearman_results = results['expected_spearman'].unstack()
    assert_frame_equal(pearson_results, expected_pearson_results)
    assert_frame_equal(spearman_results, expected_spearman_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.pearsonr(target=returns_slice, correlation_length=correlation_length)
    with self.assertRaises(TypeError):
        date_factor.spearmanr(target=returns_slice, correlation_length=correlation_length)
    with self.assertRaises(TypeError):
        returns.pearsonr(target=date_factor_slice, correlation_length=correlation_length)
    with self.assertRaises(TypeError):
        returns.pearsonr(target=date_factor_slice, correlation_length=correlation_length)
