From 476a69da3c435c9570aa36cf1ad78eba88d37ffe Mon Sep 17 00:00:00 2001 From: Warren Weckesser Date: Sun, 6 Aug 2023 13:16:00 -0400 Subject: [PATCH] BUG: polynomial: Handle non-array inputs in polynomial class __call__ method. (#24349) Use the utility function `polyutils.mapdomain()` in the `__call__` method of `ABCPolyBase`. This closes gh-17949 because `mapdomain` calls `np.asanyarray(x)` on its first argument. Closes gh-17949. --- numpy/polynomial/_polybase.py | 3 +-- numpy/polynomial/tests/test_classes.py | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py index 9730574cf22e..e967833230ad 100644 --- a/numpy/polynomial/_polybase.py +++ b/numpy/polynomial/_polybase.py @@ -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): diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py index 6322062f29ec..c5b6feb1171b 100644 --- a/numpy/polynomial/tests/test_classes.py +++ b/numpy/polynomial/tests/test_classes.py @@ -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)