Skip to content

Commit 6757fda

Browse files
authored
Merge pull request scipy#20588 from j-bowhay/comb_dep
2 parents f139e75 + 38fcc9b commit 6757fda

File tree

3 files changed

+15
-82
lines changed

3 files changed

+15
-82
lines changed

scipy/special/_basic.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
_sph_harm_all as _sph_harm_all_gufunc)
1919
from . import _specfun
2020
from ._comb import _comb_int
21-
from scipy._lib.deprecation import _NoValue, _deprecate_positional_args
2221

2322

2423
__all__ = [
@@ -2679,8 +2678,7 @@ def obl_cv_seq(m, n, c):
26792678
return _specfun.segv(m, n, c, -1)[1][:maxL]
26802679

26812680

2682-
@_deprecate_positional_args(version="1.14")
2683-
def comb(N, k, *, exact=False, repetition=False, legacy=_NoValue):
2681+
def comb(N, k, *, exact=False, repetition=False):
26842682
"""The number of combinations of N things taken k at a time.
26852683
26862684
This is often expressed as "N choose k".
@@ -2693,21 +2691,10 @@ def comb(N, k, *, exact=False, repetition=False, legacy=_NoValue):
26932691
Number of elements taken.
26942692
exact : bool, optional
26952693
For integers, if `exact` is False, then floating point precision is
2696-
used, otherwise the result is computed exactly. For non-integers, if
2697-
`exact` is True, is disregarded.
2694+
used, otherwise the result is computed exactly.
26982695
repetition : bool, optional
26992696
If `repetition` is True, then the number of combinations with
27002697
repetition is computed.
2701-
legacy : bool, optional
2702-
If `legacy` is True and `exact` is True, then non-integral arguments
2703-
are cast to ints; if `legacy` is False, the result for non-integral
2704-
arguments is unaffected by the value of `exact`.
2705-
2706-
.. deprecated:: 1.9.0
2707-
Using `legacy` is deprecated and will removed by
2708-
Scipy 1.14.0. If you want to keep the legacy behaviour, cast
2709-
your inputs directly, e.g.
2710-
``comb(int(your_N), int(your_k), exact=True)``.
27112698
27122699
Returns
27132700
-------
@@ -2739,25 +2726,12 @@ def comb(N, k, *, exact=False, repetition=False, legacy=_NoValue):
27392726
220
27402727
27412728
"""
2742-
if legacy is not _NoValue:
2743-
warnings.warn(
2744-
"Using 'legacy' keyword is deprecated and will be removed by "
2745-
"Scipy 1.14.0. If you want to keep the legacy behaviour, cast "
2746-
"your inputs directly, e.g. "
2747-
"'comb(int(your_N), int(your_k), exact=True)'.",
2748-
DeprecationWarning,
2749-
stacklevel=2
2750-
)
27512729
if repetition:
2752-
return comb(N + k - 1, k, exact=exact, legacy=legacy)
2730+
return comb(N + k - 1, k, exact=exact)
27532731
if exact:
27542732
if int(N) == N and int(k) == k:
27552733
# _comb_int casts inputs to integers, which is safe & intended here
27562734
return _comb_int(N, k)
2757-
elif legacy:
2758-
# here at least one number is not an integer; legacy behavior uses
2759-
# lossy casts to int
2760-
return _comb_int(N, k)
27612735
# otherwise, we disregard `exact=True`; it makes no sense for
27622736
# non-integral arguments
27632737
return comb(N, k)

scipy/special/_special_ufuncs_docs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,16 @@ const char *binom_doc = R"(
398398
``y`` is negative or ``x`` is less than ``y``.
399399
400400
>>> x, y = -3, 2
401-
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
402-
(nan, 0.0, 0)
401+
>>> (binom(x, y), comb(x, y))
402+
(nan, 0.0)
403403
404404
>>> x, y = -3.1, 2.2
405-
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
406-
(18.714147876804432, 0.0, 0)
405+
>>> (binom(x, y), comb(x, y))
406+
(18.714147876804432, 0.0)
407407
408408
>>> x, y = 2.2, 3.1
409-
>>> (binom(x, y), comb(x, y), comb(x, y, exact=True))
410-
(0.037399983365134115, 0.0, 0)
409+
>>> (binom(x, y), comb(x, y))
410+
(0.037399983365134115, 0.0)
411411
)";
412412

413413
const char *exp1_doc = R"(

scipy/special/tests/test_basic.py

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from scipy.special import ellipe, ellipk, ellipkm1
4141
from scipy.special import elliprc, elliprd, elliprf, elliprg, elliprj
4242
from scipy.special import mathieu_odd_coef, mathieu_even_coef, stirling2
43-
from scipy._lib.deprecation import _NoValue
4443
from scipy._lib._util import np_long, np_ulong
4544

4645
from scipy.special._basic import _FACTORIALK_LIMITS_64BITS, \
@@ -1429,8 +1428,8 @@ def test_betainc_domain_errors(self, func, args):
14291428

14301429
class TestCombinatorics:
14311430
def test_comb(self):
1432-
assert_array_almost_equal(special.comb([10, 10], [3, 4]), [120., 210.])
1433-
assert_almost_equal(special.comb(10, 3), 120.)
1431+
assert_allclose(special.comb([10, 10], [3, 4]), [120., 210.])
1432+
assert_allclose(special.comb(10, 3), 120.)
14341433
assert_equal(special.comb(10, 3, exact=True), 120)
14351434
assert_equal(special.comb(10, 3, exact=True, repetition=True), 220)
14361435

@@ -1443,39 +1442,6 @@ def test_comb(self):
14431442
expected = 100891344545564193334812497256
14441443
assert special.comb(100, 50, exact=True) == expected
14451444

1446-
@pytest.mark.parametrize("repetition", [True, False])
1447-
@pytest.mark.parametrize("legacy", [True, False, _NoValue])
1448-
@pytest.mark.parametrize("k", [3.5, 3])
1449-
@pytest.mark.parametrize("N", [4.5, 4])
1450-
def test_comb_legacy(self, N, k, legacy, repetition):
1451-
# test is only relevant for exact=True
1452-
if legacy is not _NoValue:
1453-
with pytest.warns(
1454-
DeprecationWarning,
1455-
match=r"Using 'legacy' keyword is deprecated"
1456-
):
1457-
result = special.comb(N, k, exact=True, legacy=legacy,
1458-
repetition=repetition)
1459-
else:
1460-
result = special.comb(N, k, exact=True, legacy=legacy,
1461-
repetition=repetition)
1462-
if legacy:
1463-
# for exact=True and legacy=True, cast input arguments, else don't
1464-
if repetition:
1465-
# the casting in legacy mode happens AFTER transforming N & k,
1466-
# so rounding can change (e.g. both floats, but sum to int);
1467-
# hence we need to emulate the repetition-transformation here
1468-
N, k = int(N + k - 1), int(k)
1469-
repetition = False
1470-
else:
1471-
N, k = int(N), int(k)
1472-
# expected result is the same as with exact=False
1473-
with suppress_warnings() as sup:
1474-
if legacy is not _NoValue:
1475-
sup.filter(DeprecationWarning)
1476-
expected = special.comb(N, k, legacy=legacy, repetition=repetition)
1477-
assert_equal(result, expected)
1478-
14791445
def test_comb_with_np_int64(self):
14801446
n = 70
14811447
k = 30
@@ -1490,11 +1456,10 @@ def test_comb_zeros(self):
14901456
assert_equal(special.comb(-1, 3, exact=True), 0)
14911457
assert_equal(special.comb(2, -1, exact=True), 0)
14921458
assert_equal(special.comb(2, -1, exact=False), 0)
1493-
assert_array_almost_equal(special.comb([2, -1, 2, 10], [3, 3, -1, 3]),
1494-
[0., 0., 0., 120.])
1459+
assert_allclose(special.comb([2, -1, 2, 10], [3, 3, -1, 3]), [0., 0., 0., 120.])
14951460

14961461
def test_perm(self):
1497-
assert_array_almost_equal(special.perm([10, 10], [3, 4]), [720., 5040.])
1462+
assert_allclose(special.perm([10, 10], [3, 4]), [720., 5040.])
14981463
assert_almost_equal(special.perm(10, 3), 720.)
14991464
assert_equal(special.perm(10, 3, exact=True), 720)
15001465

@@ -1503,14 +1468,8 @@ def test_perm_zeros(self):
15031468
assert_equal(special.perm(-1, 3, exact=True), 0)
15041469
assert_equal(special.perm(2, -1, exact=True), 0)
15051470
assert_equal(special.perm(2, -1, exact=False), 0)
1506-
assert_array_almost_equal(special.perm([2, -1, 2, 10], [3, 3, -1, 3]),
1507-
[0., 0., 0., 720.])
1508-
1509-
def test_positional_deprecation(self):
1510-
with pytest.deprecated_call(match="use keyword arguments"):
1511-
# from test_comb
1512-
special.comb([10, 10], [3, 4], False, False)
1513-
1471+
assert_allclose(special.perm([2, -1, 2, 10], [3, 3, -1, 3]), [0., 0., 0., 720.])
1472+
15141473

15151474
class TestTrigonometric:
15161475
def test_cbrt(self):

0 commit comments

Comments
 (0)