Skip to content

BUG: Inconsistent RuntimeWarnings "invalid value encountered in reduce" #22661

@bersbersbers

Description

@bersbersbers

Describe the issue:

I get warnings when summing Inf and -Inf (which is NaN), but not when summing 5 and NaN (which is NaN) nor when summing Inf and Inf.

I would prefer not seeing a warning in any of these cases.

Reproduce the code example:

# Warning:
python -c "import numpy as np; print(np.sum([np.Inf, -np.Inf]))"

# No warning:
python -c "import numpy as np; print(np.sum([5, np.nan]))"   
python -c "import numpy as np; print(np.sum([np.Inf, np.Inf]))"

Error message:

site-packages\numpy\core\fromnumeric.py:86: RuntimeWarning: invalid value encountered in reduce
  return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

NumPy/Python version information:

1.23.4 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]

Context for the issue:

See also https://stackoverflow.com/q/74552683/880783

Metadata

Metadata

Assignees

No one assigned

    Labels

    33 - QuestionQuestion about NumPy usage or development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions