Skip to content

Commit

Permalink
BUG: polynomial: Handle non-array inputs in polynomial class __call__…
Browse files Browse the repository at this point in the history
… method. (numpy#24349)

Use the utility function `polyutils.mapdomain()` in the `__call__` method of
`ABCPolyBase`.  This closes numpygh-17949 because `mapdomain` calls `np.asanyarray(x)`
on its first argument.

Closes numpygh-17949.
  • Loading branch information
WarrenWeckesser authored Aug 6, 2023
1 parent 8627dc9 commit 476a69d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions numpy/polynomial/_polybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ def __setstate__(self, dict):
# Call

def __call__(self, arg):
off, scl = pu.mapparms(self.domain, self.window)
arg = off + scl*arg
arg = pu.mapdomain(arg, self.domain, self.window)
return self._val(arg, self.coef)

def __iter__(self):
Expand Down
7 changes: 7 additions & 0 deletions numpy/polynomial/tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ def test_call(Poly):
assert_almost_equal(res, tgt)


def test_call_with_list(Poly):
p = Poly([1, 2, 3])
x = [-1, 0, 2]
res = p(x)
assert_equal(res, p(np.array(x)))


def test_cutdeg(Poly):
p = Poly([1, 2, 3])
assert_raises(ValueError, p.cutdeg, .5)
Expand Down

0 comments on commit 476a69d

Please sign in to comment.