Skip to content

TST Fix scipy DeprecationWarning from wminkowski in nightly - #18930

Merged
thomasjpfan merged 12 commits into
scikit-learn:masterfrom
cmarmo:scipy-wminkowski
Jan 2, 2021
Merged

thomasjpfan merged 12 commits into
scikit-learn:masterfrom
cmarmo:scipy-wminkowski

Conversation

@cmarmo

@cmarmo cmarmo commented Nov 27, 2020

Copy link
Copy Markdown
Contributor

What does this implement/fix? Explain your changes.

This pull request modifies tests to use 'minkoski' metrics when 'wminkowski' is called when scipy version is >= 1.6.
This remove some DeprecationWarnings in the nightly build.

Any other comments?

  • I'm under the impression that the minkoski metrics is already called with a 'w' argument
    _wminkowski_kwds = {'w': np.arange(1, 5).astype('double', copy=False), 'p': 1}
  • Should I raise a sklearn DeprecationWarning for 'wminkowski' metric (called in sklearn/metrics/pairwise.py) or we can rely on the scipy one? Thanks!

Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
@ogrisel

ogrisel commented Nov 27, 2020

Copy link
Copy Markdown
Member

Should I raise a sklearn DeprecationWarning for 'wminkowski' metric (called in sklearn/metrics/pairwise.py) or we can rely on the scipy one? Thanks!

I think we can rely on scipy one for simplicity. Maybe we could upgrade the test to also check minkowski with the w parameter in versions before 1.6.

I am running scipy 1.5 and this w parameter is already present.

@ogrisel

ogrisel commented Nov 30, 2020

Copy link
Copy Markdown
Member

The second part of my comment was not addressed:

Maybe we could upgrade the test to also check minkowski with the w parameter in versions before 1.6. I am running scipy 1.5 and this w parameter is already present.

Can you give it a try?

The oldest version of scipy we support (0.19.1 as defined in sklearn._min_dependencies) does not have the w parameter for the minkowski function but scipy 1.0 and later do. So we could just skip this particular test parametrization for sp_version < parse_version("1.0") using an explicit call to pytest.skip such as: pytest.skip("minkowski does not accept the w parameter prior to scipy 1.0").

@cmarmo

cmarmo commented Nov 30, 2020

Copy link
Copy Markdown
Contributor Author

I'm sorry @ogrisel, I was having a blind spot on the w. I see now that the arguments are not defined for minkowsky, they are only for wminkowsky. I will add the test ASAP.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ogrisel

ogrisel commented Dec 15, 2020

Copy link
Copy Markdown
Member

We can ignore the coverage failure because all the cases cannot be tested prior to the scipy 1.6 release but the code looks correct. And even if it is not, the nightly builds will catch it quickly after the merge of this PR.

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @cmarmo !

except ImportError:
# In scipy 1.6.0, wminkowski is deprecated and minkowski
# should be used instead.
from scipy.spatial.distance import minkowski as wminkowski

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for coverage, the ImportError will not trigger until scipy 1.8 is released and wminkowski is removed.

(This is a comment: no changes required here)

Comment thread sklearn/metrics/tests/test_pairwise.py Outdated
if sp_version >= parse_version("1.6.0") and (
metric == wminkowski or metric == 'wminkowski'
):
metric = 'minkowski'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we can skip because minkowski is tested explicitly and this would be testing it again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand correctly: I have then skipped the wminkowski and 'wminkowski' test for scipy >=1.6.0, Is that what you meant? Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have then skipped the wminkowski and 'wminkowski' test for scipy >=1.6.0, Is that what you meant?

Yes this is what I meant.

I think we can skip here because this PR adds metric = 'minkowski' to pytest.mark.parameterize, so metric = 'minkowski' will get tested when it gets to that test case.

Comment thread sklearn/metrics/tests/test_pairwise.py Outdated
@pytest.mark.parametrize(
'func, metric, kwds',
[(pairwise_distances, 'euclidean', {}),
(pairwise_distances, minkowski, _minkowski_kwds),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can include the skip here:

Suggested change
(pairwise_distances, minkowski, _minkowski_kwds),
pytest.param(pairwise_distances, minkowski, _minkowski_kwds,
marks=pytest.mark.skipif(sp_version < parse_version("1.0")),
reason="minkoski does not accept ..."),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this kind of parametrization should be applied to the 'minkowsi' case too, right?

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan changed the title Fix scipy DeprecationWarning from wminkowski in nightly build TST Fix scipy DeprecationWarning from wminkowski in nightly Jan 2, 2021
@thomasjpfan
thomasjpfan merged commit b7a48a0 into scikit-learn:master Jan 2, 2021
@thomasjpfan

Copy link
Copy Markdown
Member

Currently, the nightly build is not able to run without #19062 merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants