From b527c805558e06445dce4173aa3d024634817b33 Mon Sep 17 00:00:00 2001 From: Meekail Zain Date: Wed, 15 Jun 2022 17:32:13 -0400 Subject: [PATCH 1/3] Compensated for changes in `stats.mode` to keep internal behavior --- sklearn/utils/tests/test_extmath.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/utils/tests/test_extmath.py b/sklearn/utils/tests/test_extmath.py index 07a553c8cf09d..cf3c2548d3d98 100644 --- a/sklearn/utils/tests/test_extmath.py +++ b/sklearn/utils/tests/test_extmath.py @@ -58,6 +58,9 @@ def test_uniform_weights(): for axis in (None, 0, 1): mode, score = stats.mode(x, axis) mode2, score2 = weighted_mode(x, weights, axis=axis) + if axis is not None: + mode = np.expand_dims(mode, axis=axis) + score = np.expand_dims(score, axis=axis) assert_array_equal(mode, mode2) assert_array_equal(score, score2) From 553f28d9bc34007207e176cae94514094ae2481b Mon Sep 17 00:00:00 2001 From: Meekail Zain Date: Thu, 16 Jun 2022 10:07:27 -0400 Subject: [PATCH 2/3] Updated test to only add axis for new scipy version --- sklearn/utils/tests/test_extmath.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sklearn/utils/tests/test_extmath.py b/sklearn/utils/tests/test_extmath.py index cf3c2548d3d98..bbde65ac778cf 100644 --- a/sklearn/utils/tests/test_extmath.py +++ b/sklearn/utils/tests/test_extmath.py @@ -4,6 +4,7 @@ # # License: BSD 3 clause import numpy as np +import scipy from scipy import sparse from scipy import linalg from scipy import stats @@ -33,6 +34,9 @@ from sklearn.utils.extmath import stable_cumsum from sklearn.utils.extmath import safe_sparse_dot from sklearn.datasets import make_low_rank_matrix, make_sparse_spd_matrix +from sklearn.externals._packaging.version import parse as parse_version + +sp_version = parse_version(scipy.__version__) def test_density(): @@ -58,7 +62,8 @@ def test_uniform_weights(): for axis in (None, 0, 1): mode, score = stats.mode(x, axis) mode2, score2 = weighted_mode(x, weights, axis=axis) - if axis is not None: + + if sp_version >= parse_version("1.9.0") and axis is not None: mode = np.expand_dims(mode, axis=axis) score = np.expand_dims(score, axis=axis) From 9f75b2f737a7a6b2dd5270bdba0ed1cecf8fc861 Mon Sep 17 00:00:00 2001 From: Meekail Zain Date: Thu, 16 Jun 2022 10:19:24 -0400 Subject: [PATCH 3/3] Added clarifying comment --- sklearn/utils/tests/test_extmath.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/utils/tests/test_extmath.py b/sklearn/utils/tests/test_extmath.py index bbde65ac778cf..8fbc66e5e8e96 100644 --- a/sklearn/utils/tests/test_extmath.py +++ b/sklearn/utils/tests/test_extmath.py @@ -63,6 +63,7 @@ def test_uniform_weights(): mode, score = stats.mode(x, axis) mode2, score2 = weighted_mode(x, weights, axis=axis) + # See https://github.com/scipy/scipy/issues/16418 if sp_version >= parse_version("1.9.0") and axis is not None: mode = np.expand_dims(mode, axis=axis) score = np.expand_dims(score, axis=axis)