Skip to content

Commit af521da

Browse files
authored
Merge pull request scipy#22087 from j-bowhay/exact_dep
DEP: special: raise error for non-integer types with exact=True for comb and perm
2 parents 7eb7ecf + 8932346 commit af521da

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

scipy/special/_basic.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,12 +2728,9 @@ def comb(N, k, *, exact=False, repetition=False):
27282728
if int(N) == N and int(k) == k:
27292729
# _comb_int casts inputs to integers, which is safe & intended here
27302730
return _comb_int(N, k)
2731-
# otherwise, we disregard `exact=True`; it makes no sense for
2732-
# non-integral arguments
2733-
msg = ("`exact=True` is deprecated for non-integer `N` and `k` and will raise "
2734-
"an error in SciPy 1.16.0")
2735-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
2736-
return comb(N, k)
2731+
else:
2732+
raise ValueError("Non-integer `N` and `k` with `exact=True` is not "
2733+
"supported.")
27372734
else:
27382735
k, N = asarray(k), asarray(N)
27392736
cond = (k <= N) & (N >= 0) & (k >= 0)
@@ -2787,19 +2784,17 @@ def perm(N, k, exact=False):
27872784
N = np.squeeze(N)[()] # for backward compatibility (accepted size 1 arrays)
27882785
k = np.squeeze(k)[()]
27892786
if not (isscalar(N) and isscalar(k)):
2790-
raise ValueError("`N` and `k` must scalar integers be with `exact=True`.")
2787+
raise ValueError("`N` and `k` must be scalar integers with `exact=True`.")
27912788

27922789
floor_N, floor_k = int(N), int(k)
27932790
non_integral = not (floor_N == N and floor_k == k)
2794-
if (k > N) or (N < 0) or (k < 0):
2795-
if non_integral:
2796-
msg = ("Non-integer `N` and `k` with `exact=True` is deprecated and "
2797-
"will raise an error in SciPy 1.16.0.")
2798-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
2799-
return 0
28002791
if non_integral:
28012792
raise ValueError("Non-integer `N` and `k` with `exact=True` is not "
28022793
"supported.")
2794+
2795+
if (k > N) or (N < 0) or (k < 0):
2796+
return 0
2797+
28032798
val = 1
28042799
for i in range(floor_N - floor_k + 1, floor_N + 1):
28052800
val *= i

scipy/special/tests/test_basic.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,13 @@ def test_comb_zeros(self):
14911491
assert_allclose(special.comb([2, -1, 2, 10], [3, 3, -1, 3]), [0., 0., 0., 120.])
14921492

14931493
@pytest.mark.thread_unsafe
1494-
def test_comb_exact_non_int_dep(self):
1494+
def test_comb_exact_non_int_error(self):
14951495
msg = "`exact=True`"
1496-
with pytest.deprecated_call(match=msg):
1496+
with pytest.raises(ValueError, match=msg):
14971497
special.comb(3.4, 4, exact=True)
1498+
with pytest.raises(ValueError, match=msg):
1499+
special.comb(3, 4.4, exact=True)
1500+
14981501

14991502
def test_perm(self):
15001503
assert_allclose(special.perm([10, 10], [3, 4]), [720., 5040.])
@@ -1514,17 +1517,12 @@ def test_perm_iv(self):
15141517
with pytest.raises(ValueError, match="scalar integers"):
15151518
special.perm([1, 2], [4, 5], exact=True)
15161519

1517-
# Non-integral scalars with N < k, or N,k < 0 used to return 0, this is now
1518-
# deprecated and will raise an error in SciPy 1.16.0
1519-
with pytest.deprecated_call(match="Non-integer"):
1520+
with pytest.raises(ValueError, match="Non-integer"):
15201521
special.perm(4.6, 6, exact=True)
1521-
with pytest.deprecated_call(match="Non-integer"):
1522+
with pytest.raises(ValueError, match="Non-integer"):
15221523
special.perm(-4.6, 3, exact=True)
1523-
with pytest.deprecated_call(match="Non-integer"):
1524+
with pytest.raises(ValueError, match="Non-integer"):
15241525
special.perm(4, -3.9, exact=True)
1525-
1526-
# Non-integral scalars which aren't included in the cases above an raise an
1527-
# error directly without deprecation as this code never worked
15281526
with pytest.raises(ValueError, match="Non-integer"):
15291527
special.perm(6.0, 4.6, exact=True)
15301528

0 commit comments

Comments
 (0)