10000 add test case for scipy version UserWarning · scikit-learn/scikit-learn@8579f6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8579f6f

Browse files
committed
add test case for scipy version UserWarning
1 parent 27cb5b8 commit 8579f6f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sklearn/utils/tests/test_array_api.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from functools import partial
34

@@ -76,7 +77,7 @@ def test_get_namespace_ndarray_with_dispatch():
7677

7778

7879
@skip_if_array_api_compat_not_configured
79-
def test_get_namespace_array_api():
80+
def test_get_namespace_array_api(monkeypatch):
8081
"""Test get_namespace for ArrayAPI arrays."""
8182
xp = pytest.importorskip("array_api_strict")
8283

@@ -89,6 +90,19 @@ def test_get_namespace_array_api():
8990
with pytest.raises(TypeError):
9091
xp_out, is_array_api_compliant = get_namespace(X_xp, X_np)
9192

93+
def mock_getenv(key):
94+
if key == "SCIPY_ARRAY_API":
95+
return "0"
96+
return None
97+
98+
monkeypatch.setattr("os.environ.get", mock_getenv)
99+
assert os.environ.get("SCIPY_ARRAY_API") != "1"
100+
with pytest.warns(
101+
UserWarning,
102+
match="enabling SciPy's own support for array API to function properly. ",
103+
):
104+
xp_out, is_array_api_compliant = get_namespace(X_xp)
105+
92106

93107
class _AdjustableNameAPITestWrapper(_ArrayAPIWrapper):
94108
"""API wrapper that has an adjustable name. Used for testing."""

0 commit comments

Comments
 (0)
0