scikit-learn-contrib / imbalanced-learn

A Python Package to Tackle the Curse of Imbalanced Datasets in Machine Learning
https://imbalanced-learn.org
MIT License
6.85k stars 1.29k forks source link

[BUG] Pytest fails on latest version #1095

Closed Arjun31415 closed 1 month ago

Arjun31415 commented 2 months ago

Describe the bug

imblearn fails to pass pytests. I would suspect it is something related to scipy 1.14 because of a similar issue here https://github.com/theislab/scvelo/issues/1260

Steps/Code to Reproduce

git clone --recursive https://github.com/scikit-learn-contrib/imbalanced-learn
cd imbalanced-learn
pytest

Expected Results

Tests are successful

Actual Results

=
___________________________________________________ test_estimators_imblearn[AllKNN()-check_samplers_sparse] ___________________________________________________

estimator = AllKNN(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'AllKNN')
request = <FixtureRequest for <Function test_estimators_imblearn[AllKNN()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'AllKNN', sampler_orig = AllKNN()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_______________________________________ test_estimators_imblearn[BorderlineSMOTE(random_state=0)-check_samplers_sparse] ________________________________________

estimator = BorderlineSMOTE(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'BorderlineSMOTE')
request = <FixtureRequest for <Function test_estimators_imblearn[BorderlineSMOTE(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'BorderlineSMOTE', sampler_orig = BorderlineSMOTE(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_______________________________________ test_estimators_imblearn[ClusterCentroids(random_state=0)-check_samplers_sparse] _______________________________________

estimator = ClusterCentroids(estimator=KMeans(n_init=1, random_state=0), random_state=0,
                 voting='soft')
check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'ClusterCentroids')
request = <FixtureRequest for <Function test_estimators_imblearn[ClusterCentroids(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'ClusterCentroids', sampler_orig = ClusterCentroids(estimator=KMeans(n_init=1, random_state=0), random_state=0,
                 voting='soft')

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
__________________________________ test_estimators_imblearn[CondensedNearestNeighbour(random_state=0)-check_samplers_sparse] ___________________________________

estimator = CondensedNearestNeighbour(random_state=0)
check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'CondensedNearestNeighbour')
request = <FixtureRequest for <Function test_estimators_imblearn[CondensedNearestNeighbour(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'CondensedNearestNeighbour', sampler_orig = CondensedNearestNeighbour(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
__________________________________________ test_estimators_imblearn[EditedNearestNeighbours()-check_samplers_sparse] ___________________________________________

estimator = EditedNearestNeighbours(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'EditedNearestNeighbours')
request = <FixtureRequest for <Function test_estimators_imblearn[EditedNearestNeighbours()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'EditedNearestNeighbours', sampler_orig = EditedNearestNeighbours()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
______________________________________________ test_estimators_imblearn[FunctionSampler()-check_samplers_sparse] _______________________________________________

estimator = FunctionSampler(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'FunctionSampler')
request = <FixtureRequest for <Function test_estimators_imblearn[FunctionSampler()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'FunctionSampler', sampler_orig = FunctionSampler()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
__________________________________ test_estimators_imblearn[InstanceHardnessThreshold(random_state=0)-check_samplers_sparse] ___________________________________

estimator = InstanceHardnessThreshold(random_state=0)
check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'InstanceHardnessThreshold')
request = <FixtureRequest for <Function test_estimators_imblearn[InstanceHardnessThreshold(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'InstanceHardnessThreshold', sampler_orig = InstanceHardnessThreshold(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_________________________________________ test_estimators_imblearn[KMeansSMOTE(random_state=0)-check_samplers_sparse] __________________________________________

estimator = KMeansSMOTE(kmeans_estimator=12, random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'KMeansSMOTE')
request = <FixtureRequest for <Function test_estimators_imblearn[KMeansSMOTE(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'KMeansSMOTE', sampler_orig = KMeansSMOTE(kmeans_estimator=12, random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
__________________________________________________ test_estimators_imblearn[NearMiss()-check_samplers_sparse] __________________________________________________

estimator = NearMiss(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'NearMiss')
request = <FixtureRequest for <Function test_estimators_imblearn[NearMiss()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'NearMiss', sampler_orig = NearMiss()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_____________________________________________ test_estimators_imblearn[NearMiss(version=2)-check_samplers_sparse] ______________________________________________

estimator = NearMiss(version=2), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'NearMiss')
request = <FixtureRequest for <Function test_estimators_imblearn[NearMiss(version=2)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'NearMiss', sampler_orig = NearMiss(version=2)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_____________________________________________ test_estimators_imblearn[NearMiss(version=3)-check_samplers_sparse] ______________________________________________

estimator = NearMiss(version=3), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'NearMiss')
request = <FixtureRequest for <Function test_estimators_imblearn[NearMiss(version=3)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'NearMiss', sampler_orig = NearMiss(version=3)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_________________________________________ test_estimators_imblearn[NeighbourhoodCleaningRule()-check_samplers_sparse] __________________________________________

estimator = NeighbourhoodCleaningRule(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'NeighbourhoodCleaningRule')
request = <FixtureRequest for <Function test_estimators_imblearn[NeighbourhoodCleaningRule()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'NeighbourhoodCleaningRule', sampler_orig = NeighbourhoodCleaningRule()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
______________________________________ test_estimators_imblearn[OneSidedSelection(random_state=0)-check_samplers_sparse] _______________________________________

estimator = OneSidedSelection(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'OneSidedSelection')
request = <FixtureRequest for <Function test_estimators_imblearn[OneSidedSelection(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'OneSidedSelection', sampler_orig = OneSidedSelection(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
______________________________________ test_estimators_imblearn[RandomOverSampler(random_state=0)-check_samplers_sparse] _______________________________________

estimator = RandomOverSampler(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'RandomOverSampler')
request = <FixtureRequest for <Function test_estimators_imblearn[RandomOverSampler(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'RandomOverSampler', sampler_orig = RandomOverSampler(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
______________________________________ test_estimators_imblearn[RandomUnderSampler(random_state=0)-check_samplers_sparse] ______________________________________

estimator = RandomUnderSampler(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'RandomUnderSampler')
request = <FixtureRequest for <Function test_estimators_imblearn[RandomUnderSampler(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'RandomUnderSampler', sampler_orig = RandomUnderSampler(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
______________________________________ test_estimators_imblearn[RepeatedEditedNearestNeighbours()-check_samplers_sparse] _______________________________________

estimator = RepeatedEditedNearestNeighbours(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'RepeatedEditedNearestNeighbours')
request = <FixtureRequest for <Function test_estimators_imblearn[RepeatedEditedNearestNeighbours()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'RepeatedEditedNearestNeighbours', sampler_orig = RepeatedEditedNearestNeighbours()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
____________________________________________ test_estimators_imblearn[SMOTE(random_state=0)-check_samplers_sparse] _____________________________________________

estimator = SMOTE(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'SMOTE')
request = <FixtureRequest for <Function test_estimators_imblearn[SMOTE(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'SMOTE', sampler_orig = SMOTE(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
___________________________________________ test_estimators_imblearn[SMOTEENN(random_state=0)-check_samplers_sparse] ___________________________________________

estimator = SMOTEENN(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'SMOTEENN')
request = <FixtureRequest for <Function test_estimators_imblearn[SMOTEENN(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'SMOTEENN', sampler_orig = SMOTEENN(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
__________________________________________ test_estimators_imblearn[SMOTETomek(random_state=0)-check_samplers_sparse] __________________________________________

estimator = SMOTETomek(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'SMOTETomek')
request = <FixtureRequest for <Function test_estimators_imblearn[SMOTETomek(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'SMOTETomek', sampler_orig = SMOTETomek(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
___________________________________________ test_estimators_imblearn[SVMSMOTE(random_state=0)-check_samplers_sparse] ___________________________________________

estimator = SVMSMOTE(random_state=0), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'SVMSMOTE')
request = <FixtureRequest for <Function test_estimators_imblearn[SVMSMOTE(random_state=0)-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'SVMSMOTE', sampler_orig = SVMSMOTE(random_state=0)

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
_________________________________________________ test_estimators_imblearn[TomekLinks()-check_samplers_sparse] _________________________________________________

estimator = TomekLinks(), check = functools.partial(<function check_samplers_sparse at 0x7ffeeb575300>, 'TomekLinks')
request = <FixtureRequest for <Function test_estimators_imblearn[TomekLinks()-check_samplers_sparse]>>

    @parametrize_with_checks(list(_tested_estimators()))
    def test_estimators_imblearn(estimator, check, request):
        # Common tests for estimator instances
        with ignore_warnings(
            category=(
                FutureWarning,
                ConvergenceWarning,
                UserWarning,
                FutureWarning,
            )
        ):
            _set_checking_parameters(estimator)
>           check(estimator)

imblearn/tests/test_common.py:71: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'TomekLinks', sampler_orig = TomekLinks()

    def check_samplers_sparse(name, sampler_orig):
        sampler = clone(sampler_orig)
        # check that sparse matrices can be passed through the sampler leading to
        # the same results than dense
        X, y = sample_dataset_generator()
        X_sparse = sparse.csr_matrix(X)
        X_res_sparse, y_res_sparse = sampler.fit_resample(X_sparse, y)
        sampler = clone(sampler)
        X_res, y_res = sampler.fit_resample(X, y)
        assert sparse.issparse(X_res_sparse)
>       assert_allclose(X_res_sparse.A, X_res, rtol=1e-5)
E       AttributeError: 'csr_matrix' object has no attribute 'A'

imblearn/utils/estimator_checks.py:312: AttributeError
=

Versions

Please run the following snippet and paste the output below. For scikit-learn >= 0.20:

import sklearn; sklearn.show_versions()
System:
    python: 3.12.5 (main, Aug  6 2024, 19:08:49) [GCC 13.3.0]
executable: /nix/store/h3i0acpmr8mrjx07519xxmidv8mpax4y-python3-3.12.5/bin/python
   machine: Linux-6.11.0-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.5.0
          pip: None
   setuptools: None
        numpy: 1.26.4
        scipy: 1.14.0
       Cython: None
       pandas: 2.2.2
   matplotlib: 3.9.1
       joblib: 1.4.2
threadpoolctl: 3.4.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libgomp
       filepath: /nix/store/22nxhmsfcv2q2rpkmfvzwg2w5z1l231z-gcc-13.3.0-lib/lib/libgomp.so.1.0.0
        version: None
Python 3.12.5 (main, Aug  6 2024, 19:08:49) [GCC 13.3.0]
NumPy 1.26.4
SciPy 1.14.0
Scikit-Learn 1.5.0
Imbalanced-Learn 0.13.0.dev0
glemaitre commented 1 month ago

Yep, we need to use .toarray()

I'll try to adapt the code and make sure that the test suite run.

glemaitre commented 1 month ago

Fixed and released in 0.12.4