diff --git a/doc/release/1.13.0-notes.rst b/doc/release/1.13.0-notes.rst index b436a96e6a76..167b9d8945f4 100644 --- a/doc/release/1.13.0-notes.rst +++ b/doc/release/1.13.0-notes.rst @@ -415,3 +415,10 @@ greater than ``mmap.ALLOCATIONGRANULARITY``. Previously, ``np.real`` and ``np.imag`` used to return array objects when provided a scalar input, which was inconsistent with other functions like ``np.angle`` and ``np.conj``. + +The polynomial convenience classes cannot be passed to ufuncs +------------------------------------------------------------- +The ABCPolyBase class, from which the convenience classes are derived, sets +``__array_ufun__ = None`` in order of opt out of ufuncs. If a polynomial +convenience class instance is passed as an argument to a ufunc, a ``TypeError`` +will now be raised. diff --git a/numpy/polynomial/_polybase.py b/numpy/polynomial/_polybase.py index aad14738850f..39f5fac31a01 100644 --- a/numpy/polynomial/_polybase.py +++ b/numpy/polynomial/_polybase.py @@ -64,8 +64,8 @@ class ABCPolyBase(object): # Not hashable __hash__ = None - # Don't let participate in array operations. Value doesn't matter. - __array_priority__ = 1000 + # Opt out of numpy ufuncs and Python ops with ndarray subclasses. + __array_ufunc__ = None # Limit runaway size. T_n^m has degree n*m maxpower = 100 diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py index a7cf7209c6bf..46d721df41d3 100644 --- a/numpy/polynomial/tests/test_classes.py +++ b/numpy/polynomial/tests/test_classes.py @@ -53,6 +53,7 @@ def test_class_methods(): yield check_cutdeg, Poly yield check_truncate, Poly yield check_trim, Poly + yield check_ufunc_override, Poly # @@ -575,5 +576,12 @@ def check_mapparms(Poly): assert_almost_equal([1, 2], p.mapparms()) +def check_ufunc_override(Poly): + p = Poly([1, 2, 3]) + x = np.ones(3) + assert_raises(TypeError, np.add, p, x) + assert_raises(TypeError, np.add, x, p) + + if __name__ == "__main__": run_module_suite()