Skip to content

TST Fix scipy DeprecationWarning from wminkowski in nightly #18930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 2, 2021

Conversation

cmarmo
Copy link
Contributor

@cmarmo cmarmo commented Nov 27, 2020

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!

@ogrisel
Copy link
Member

ogrisel commented Nov 27, 2020

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
Copy link
Member

ogrisel commented Nov 30, 2020

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
Copy link
Contributor Author

cmarmo commented Nov 30, 2020

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.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM!

@ogrisel
Copy link
Member

ogrisel commented Dec 15, 2020

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.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

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
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)

if sp_version >= parse_version("1.6.0") and (
metric == wminkowski or metric == 'wminkowski'
):
metric = 'minkowski'
Copy link
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
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
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.

@@ -245,13 +254,26 @@ def callable_rbf_kernel(x, y, **kwds):
@pytest.mark.parametrize(
'func, metric, kwds',
[(pairwise_distances, 'euclidean', {}),
(pairwise_distances, minkowski, _minkowski_kwds),
Copy link
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
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?

Copy link
Member

@thomasjpfan thomasjpfan left a comment

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
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