Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: polyval with builtin python types for x follows NEP50 #26508

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion numpy/lib/_polynomial_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,10 @@ def polyval(p, x):

"""
p = NX.asarray(p)
if isinstance(x, poly1d):
if p.size == 0:
y, = NX.zeros(1, dtype=p.dtype)
luxedo marked this conversation as resolved.
Show resolved Hide resolved
return y
if isinstance(x, (poly1d, float, int, complex)):
y = 0
else:
x = NX.asanyarray(x)
Expand Down
13 changes: 13 additions & 0 deletions numpy/lib/tests/test_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,16 @@ def test_poly_coeffs_mutable(self):
# this never used to be allowed - let's not add features to deprecated
# APIs
assert_raises(AttributeError, setattr, p, 'coeffs', np.array(1))

def test_polyval_return_types(self):
v = np.polyval(np.array([5.], dtype=np.float32), 5.0)
assert_equal(v.dtype, np.float32)

v = np.polyval(np.array([5.], dtype=np.float16), 5.0)
assert_equal(v.dtype, np.float16)

v = np.polyval([5.], np.float16(5.0))
assert_equal(v.dtype, np.float64)

v = np.polyval(np.array([], dtype=np.float32), 5.0)
assert_equal(v.dtype, np.float32)
luxedo marked this conversation as resolved.
Show resolved Hide resolved