docstr: Ensure that `Factor.pearsonr` and `Factor.spearmanr` are consistent
  with the built-in factors `RollingPearsonOfReturns` and
  `RollingSpearmanOfReturns`.
docstr_tok: ["Ensure","that","`","Factor.pearsonr","`","and","`","Factor.spearmanr","`","are","consistent","with","the","built-in","factors","`","RollingPearsonOfReturns","`","and","`","RollingSpearmanOfReturns","`","."]
code: def test_factor_correlation_methods(
      self, returns_length, correlation_length
  ):
      """
      Ensure that `Factor.pearsonr` and `Factor.spearmanr` are consistent
      with the built-in factors `RollingPearsonOfReturns` and
      `RollingSpearmanOfReturns`.
      """
      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,
      )
  
      # These built-ins construct their own Returns factor to use as inputs,
      # so the only way to set our own inputs is to do so after the fact.
      # This should not be done in practice. It is necessary here because we
      # want Returns to use our random data as an input, but by default it is
      # using USEquityPricing.close.
      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)
  
      # Make sure we cannot call the correlation methods on factors or slices
      # of dtype `datetime64[ns]`.
      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,
          )
  
imports: from numpy import where
  from pandas import Int64Index, Timestamp
  from pandas.util.testing import assert_frame_equal
  from zipline.assets import Asset, ExchangeInfo
  from zipline.errors import NonExistentAssetInTimeFrame, NonSliceableTerm, NonWindowSafeInput, UnsupportedPipelineOutput
  from zipline.pipeline import CustomFactor, Factor, Filter, Classifier, Pipeline
  from zipline.pipeline.data import USEquityPricing
  from zipline.pipeline.data.testing import TestingDataSet
  from zipline.pipeline.domain import US_EQUITIES
  from zipline.pipeline.factors import Returns, RollingLinearRegressionOfReturns, RollingPearsonOfReturns, RollingSpearmanOfReturns, SimpleMovingAverage
  from zipline.testing import AssetID, AssetIDPlusDay, check_arrays, OpenPrice, parameter_space
  from zipline.testing.fixtures import WithSeededRandomPipelineEngine, ZiplineTestCase
  from zipline.utils.numpy_utils import datetime64ns_dtype
label_desc: Use image node_id 10 for calling the SliceTestCase obj's underlying member method code with example usage: obj.test_factor_correlation_methods(returns_length, correlation_length) without return types