Skip to content

FIX/MNT Compensated for changes in stats.mode to keep internal behavior #23640

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

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sklearn/utils/tests/test_extmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -59,6 +63,11 @@ 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)

assert_array_equal(mode, mode2)
assert_array_equal(score, score2)

Expand Down