Skip to content

Commit

Permalink
MAINT: break out test for factorialk(..., exact=None)
Browse files Browse the repository at this point in the history
avoid overloading already-complicated test_factorialk_scalar_corner_cases
even further (and prepares for upcoming changes that expand it)
  • Loading branch information
h-vetinari committed Oct 12, 2024
1 parent 41cecd0 commit 5df63a8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scipy/special/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2454,28 +2454,28 @@ def test_factorialk_array_corner_cases(self, content, dim, exact, dtype):
with pytest.raises(ValueError, match="factorialk does not*"):
special.factorialk(n, 3, exact=exact)

@pytest.mark.parametrize("exact", [True, False, None])
@pytest.mark.parametrize("exact", [True, False])
@pytest.mark.parametrize("k", range(1, 5))
@pytest.mark.parametrize("n", [1, 1.1, 2 + 2j, np.nan, None],
ids=["1", "1.1", "2+2j", "NaN", "None"])
def test_factorialk_scalar_corner_cases(self, n, k, exact):
if n is None or n is np.nan or _is_subdtype(type(n), "i"):
if exact is None:
with pytest.deprecated_call(match="factorialk will default.*"):
result = special.factorialk(n, k=k, exact=exact)
else:
# no error
result = special.factorialk(n, k=k, exact=exact)
result = special.factorialk(n, k=k, exact=exact)

nan_cond = n is np.nan or n is None
# factorialk(1, k) == 1 for all k
expected = np.nan if nan_cond else 1
assert_equal(result, expected)
else:
with pytest.raises(ValueError, match="factorialk does not*"):
with suppress_warnings() as sup:
sup.filter(DeprecationWarning, "factorialk will default")
special.factorialk(n, k=k, exact=exact)
special.factorialk(n, k=k, exact=exact)

@pytest.mark.parametrize("k", range(1, 5))
def test_factorialk_deprecation_exact(self, k):
with pytest.deprecated_call(match="factorialk will default.*"):
# leaving exact= unspecified raises warning;
# cannot happen for extend="complex" because it requires non-default exact
special.factorialk(1, k=k)

@pytest.mark.parametrize("k", [0, 1.1, np.nan, "1"])
def test_factorialk_raises_k(self, k):
Expand Down

0 comments on commit 5df63a8

Please sign in to comment.