tslearn-team / tslearn

The machine learning toolkit for time series analysis in Python
https://tslearn.readthedocs.io
BSD 2-Clause "Simplified" License
2.92k stars 342 forks source link

Fix Import Error sklearn pairwise_estimator_convert_X #435

Closed YannCabanes closed 1 year ago

YannCabanes commented 1 year ago

This PR aims at solving on ImportError on Windows and MacOS (not on Linux). In the file: tslearn/tests/sklearn_patches.py There is the import:

try:
    # Most recent
    from sklearn.utils.estimator_checks import (
        _pairwise_estimator_convert_X as pairwise_estimator_convert_X,
        _choose_check_classifiers_labels as choose_check_classifiers_labels
    )
except ImportError:
    # Deprecated from sklearn v0.24 onwards
    from sklearn.utils.estimator_checks import (
        pairwise_estimator_convert_X,
        choose_check_classifiers_labels
    )

which raises the following ImportError:

==================================== ERRORS ====================================
______________ ERROR collecting tslearn/tests/sklearn_patches.py _______________
tslearn/tests/sklearn_patches.py:56: in <module>
    from sklearn.utils.estimator_checks import (
E   ImportError: cannot import name '_pairwise_estimator_convert_X' from 'sklearn.utils.estimator_checks' (/Users/runner/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/sklearn/utils/estimator_checks.py)

During handling of the above exception, another exception occurred:
tslearn/tests/sklearn_patches.py:62: in <module>
    from sklearn.utils.estimator_checks import (
E   ImportError: cannot import name 'pairwise_estimator_convert_X' from 'sklearn.utils.estimator_checks' (/Users/runner/hostedtoolcache/Python/3.8.15/x64/lib/python3.8/site-packages/sklearn/utils/estimator_checks.py)
codecov-commenter commented 1 year ago

Codecov Report

Base: 94.57% // Head: 94.57% // No change to project coverage :thumbsup:

Coverage data is based on head (77717ee) compared to base (1f80e22). Patch has no changes to coverable lines.

:exclamation: Current head 77717ee differs from pull request most recent head 0ea6718. Consider uploading reports for the commit 0ea6718 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #435 +/- ## ======================================= Coverage 94.57% 94.57% ======================================= Files 62 62 Lines 4738 4738 ======================================= Hits 4481 4481 Misses 257 257 ``` Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tslearn-team). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tslearn-team)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

YannCabanes commented 1 year ago

On MacOS and Windows, specifying scikit-learn==1.0 but no tensorflow version, we obain a test error in: tslearn/tests/test_shapelets.py --> test_shapelets --> LearningShapelets

In the PR #427, we solved this problem on Linux by specifying both scikit-learn==1.0 and tensorflow==2.9.0.

We will therefore use the same specifications: scikit-learn==1.0 and tensorflow==2.9.0 in the file azure-pipelines.yml to run the continuous integration tests on MacOS and Windows.

YannCabanes commented 1 year ago

Note that this PR is due to the fact that the function: _pairwise_estimator_convert_X of the scikit-learn file sklearn.utils.estimator_checks present in scikit-learn==1.0 is missing in scikit-learn==1.2.0. (The function: _pairwise_estimator_convert_X has been removed between these two scikit-learn versions.)