diff options
author | Cameron Blocker <cameronjblocker@gmail.com> | 2020-10-17 19:00:00 -0400 |
---|---|---|
committer | Cameron Blocker <cameronjblocker@gmail.com> | 2020-10-17 19:00:00 -0400 |
commit | 56dedfc23f8f4ee0ce17c710b505254528566960 (patch) | |
tree | 32db3fabc2069521a3b493233f09071e51e0e0d9 /numpy/lib/tests/test_polynomial.py | |
parent | 7b0a764fee6e1614f3249e9082d8c4acf1dc62d5 (diff) | |
download | numpy-56dedfc23f8f4ee0ce17c710b505254528566960.tar.gz |
BUG: Respect dtype of all-zero argument to poly1d
Fixes gh-16354. Previously np.poly1d(z).coeffs.dtype would always
be np.float64 for zero array z, regardless of z's dtype.
Diffstat (limited to 'numpy/lib/tests/test_polynomial.py')
-rw-r--r-- | numpy/lib/tests/test_polynomial.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py index ab6691b43..6c3e4fa02 100644 --- a/numpy/lib/tests/test_polynomial.py +++ b/numpy/lib/tests/test_polynomial.py @@ -227,6 +227,20 @@ class TestPolynomial: v = np.arange(1, 21) assert_almost_equal(np.poly(v), np.poly(np.diag(v))) + def test_zero_poly_dtype(self): + """ + Regression test for gh-16354. + """ + z = np.array([0, 0, 0]) + p = np.poly1d(z.astype(np.int64)) + assert_equal(p.coeffs.dtype, np.int64) + + p = np.poly1d(z.astype(np.float32)) + assert_equal(p.coeffs.dtype, np.float32) + + p = np.poly1d(z.astype(np.complex64)) + assert_equal(p.coeffs.dtype, np.complex64) + def test_poly_eq(self): p = np.poly1d([1, 2, 3]) p2 = np.poly1d([1, 2, 4]) |