Skip to content

BUG: Respect dtype of all-zero argument to poly1d#17577

Merged
mattip merged 4 commits into
numpy:masterfrom
cjblocker:polymul-dtype
Oct 28, 2020
Merged

BUG: Respect dtype of all-zero argument to poly1d#17577
mattip merged 4 commits into
numpy:masterfrom
cjblocker:polymul-dtype

Conversation

@cjblocker

@cjblocker cjblocker commented Oct 17, 2020

Copy link
Copy Markdown
Contributor

Fixes gh-16354.
Previously, np.poly1d(z).coeffs.dtype would always be np.float64 for zero array z, regardless of z's dtype.

This led to unexpected dtype promotion in methods such as np.polymul:

>>> np.polymul(np.array([1, 2, 3], dtype=np.int64), np.array([0, 0, 0], dtype=np.int64)).dtype
dtype('float64')

This PR retains the dtype of zero array inputs.

>>> np.polymul(np.array([1, 2, 3], dtype=np.int64), np.array([0, 0, 0], dtype=np.int64)).dtype
dtype('int64')

Fixes numpygh-16354. Previously np.poly1d(z).coeffs.dtype would always
be np.float64 for zero array z, regardless of z's dtype.
Comment thread numpy/lib/polynomial.py Outdated

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@charris charris changed the title BUG: Respect dtype of all-zero argument to poly1d ENH: Respect dtype of all-zero argument to poly1d Oct 19, 2020
@charris charris changed the title ENH: Respect dtype of all-zero argument to poly1d BUG: Respect dtype of all-zero argument to poly1d Oct 19, 2020
@charris

charris commented Oct 19, 2020

Copy link
Copy Markdown
Member

Doctests are failing. Since this appears to change behavior it needs a release note. The release notes snippets are in doc/release/upcoming_changes, look at the other notes to see how it is done. I'd class this as needing a compatibility note.

@mattip mattip merged commit ab22e00 into numpy:master Oct 28, 2020
@mattip

mattip commented Oct 28, 2020

Copy link
Copy Markdown
Member

Thanks @cjblocker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

np.polymul return type is np.float64 or np.complex128 when given an all-zero argument

4 participants