def test_metadata_routing_with_sampler():
    """Check that we can use a sampler with metadata routing."""
    X, y = make_classification()
    cost_matrix = np.random.rand(X.shape[0], 2, 2)

    class CostSensitiveSampler(BaseSampler):
        def fit_resample(self, X, y, cost_matrix=None):
            return self._fit_resample(X, y, cost_matrix=cost_matrix)

        def _fit_resample(self, X, y, cost_matrix=None):
            self.cost_matrix_ = cost_matrix
            return X, y

    with config_context(enable_metadata_routing=True):
        sampler = CostSensitiveSampler().set_fit_resample_request(cost_matrix=True)
        pipeline = Pipeline([("sampler", sampler), ("model", LogisticRegression())])
        pipeline.fit(X, y, cost_matrix=cost_matrix)

        assert_allclose(pipeline[0].cost_matrix_, cost_matrix)
Check that we can use a sampler with metadata routing.
imblearn/tests/test_pipeline.py