numpy / numpy/numpy

BUG: Polynomial([inf]) divided by a float emits RuntimeWarning: invalid value encountered in multiply

Open
#21,358 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Describe the issue:

A Polynomial of order 0 and with coefficient value infinity emits a RuntimeWarning when dividing it by a float:

>>> Polynomial([np.inf]) / 2
RuntimeWarning: invalid value encountered in multiply
Polynomial([inf], domain=[-1.,  1.], window=[-1.,  1.])

The return value is correct, but it shouldn't emit a warning. Multiplication works fine:

>>> Polynomial([np.inf]) * 0.5
Polynomial([inf], domain=[-1.,  1.], window=[-1.,  1.])

A higher order polynomial with finite zero order coefficient works fine:

>>> Polynomial([1, np.inf]) / 2
Polynomial([0.5, inf], domain=[-1.,  1.], window=[-1.,  1.])
Reproduce the code example:
import numpy as np
from numpy.polynomial import Polynomial

Polynomial([np.inf]) / 2
Error message:
.../python3.9/site-packages/numpy/polynomial/polynomial.py:410: RuntimeWarning: invalid value encountered in multiply
  return c1/c2[-1], c1[:1]*0
NumPy/Python version information:

1.22.3 3.9.2 (default, Mar 4 2022, 13:52:40)
[GCC 9.3.0]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning with the Polynomial([np.inf]) / 2 example, then inspect numpy/polynomial/polynomial.py around the reported line 410. Check the surrounding division behavior and existing polynomial tests. Done means the same expression returns Polynomial([inf]) without emitting RuntimeWarning.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.