def test_smotenc_categorical_encoder():
    """Check that we can pass our own categorical encoder."""

    X, y, categorical_features = data_heterogneous_unordered()
    smote = SMOTENC(categorical_features=categorical_features, random_state=0)
    smote.fit_resample(X, y)

    assert getattr(smote.categorical_encoder_, "sparse_output") is True

    encoder = OneHotEncoder(sparse_output=False)
    smote.set_params(categorical_encoder=encoder).fit_resample(X, y)
    assert smote.categorical_encoder is encoder
    assert smote.categorical_encoder_ is not encoder
    assert getattr(smote.categorical_encoder_, "sparse_output") is False
Check that we can pass our own categorical encoder.
imblearn/over_sampling/_smote/tests/test_smote_nc.py