question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Docs (or implementation) for negative inputs to factorial2 are incorrect

See original GitHub issue

Describe your issue.

The docstring for factorial2 says:

If n < 0, the return value is 0.

However directly below that in the code, we can see this is not the case for n==-1

if exact:
    if n < -1:
        return 0
    if n <= 0:
        return 1

This will give a value of 1 for factorial2(-1) (if exact is false, it returns 1.0).

The code could be made consistent with the documentation (either making the result for n==-1 be 0 or saying that for n<-1, factorial2 is 0).

Alternatively, the code could be adapted to perform the extended double factorial which allows for negative inputs.

Reproducing Code Example

scipy.special.factorial(-1)

Error message

None

SciPy/NumPy/Python version information

1.7.1 1.21.2 sys.version_info(major=3, minor=9, micro=7, releaselevel=‘final’, serial=0)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
j-bowhaycommented, Feb 27, 2022

I think this can be closed gh-15592 changed the docstring to match the implementation and gh-15600 is discussing the current inconsistencies and any possible extensions.

0reactions
AvinashDwivedicommented, Feb 20, 2022

Hello is there someone who can guide me to solve this issue. I really want to do this, It will be my first contribution, Please guide me I’m a newbie

Read more comments on GitHub >

github_iconTop Results From Across the Web

BUG: handle inconsistencies in factorial functions and their ...
BUG: Docs (or implementation) for negative inputs to factorial2 are incorrect #15246. Closed. This was referenced on Mar 6.
Read more >
Testing-intro
Program testing can be used to show the presence of bugs, but never to show ... factorial2(x) == factorial(x), \ "My factorial function...
Read more >
SciPy 1.9.0 Release Notes — SciPy v1.9.3 Manual
Unlike other reduction functions, stats.mode didn't consume the axis being operated on and failed for negative axis inputs. Both the bugs have been...
Read more >
Mailman 3 ANN: SciPy 1.9.0 - NumPy-Discussion - python.org
Several BSpline methods now raise an error if inputs have ``ndim > 1``. ... DOC: False information in docs - scipy.stats.ttest_1samp * `#15700 ......
Read more >
Source code for sympy.functions.combinatorial.factorials
[docs]class factorial(CombinatorialFunction): r"""Implementation of ... is positive for every nonnegative input, and for # every odd negative input which is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found