8000 Merge pull request #9015 from charris/polynomial-ufunc-optout · numpy/numpy@e875230 · GitHub
[go: up one dir, main page]

Skip to content

Commit e875230

Browse files
authored
Merge pull request #9015 from charris/polynomial-ufunc-optout
ENH: Use `__array_ufunc__ = None` in polynomial convenience classes.
2 parents d5657b9 + 21b14aa commit e875230

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/release/1.13.0-notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,10 @@ greater than ``mmap.ALLOCATIONGRANULARITY``.
419419
Previously, ``np.real`` and ``np.imag`` used to return array objects when
420420
provided a scalar input, which was inconsistent with other functions like
421421
``np.angle`` and ``np.conj``.
422+
423+
The polynomial convenience classes cannot be passed to ufuncs
424+
-------------------------------------------------------------
425+
The ABCPolyBase class, from which the convenience classes are derived, sets
426+
``__array_ufun__ = None`` in order of opt out of ufuncs. If a polynomial
427+
convenience class instance is passed as an argument to a ufunc, a ``TypeError``
428+
will now be raised.

numpy/polynomial/_polybase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class ABCPolyBase(object):
6464
# Not hashable
6565
__hash__ = None
6666

67-
# Don't let participate in array operations. Value doesn't matter.
68-
__array_priority__ = 1000
67+
# Opt out of numpy ufuncs and Python ops with ndarray subclasses.
68+
__array_ufunc__ = None
6969

7070
# Limit runaway size. T_n^m has degree n*m
7171
maxpower = 100

numpy/polynomial/tests/test_classes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_class_methods():
5353< 9F30 div class="diff-text-inner"> yield check_cutdeg, Poly
5454
yield check_truncate, Poly
5555
yield check_trim, Poly
56+
yield check_ufunc_override, Poly
5657

5758

5859
#
@@ -575,5 +576,12 @@ def check_mapparms(Poly):
575576
assert_almost_equal([1, 2], p.mapparms())
576577

577578

579+
def check_ufunc_override(Poly):
580+
p = Poly([1, 2, 3])
581+
x = np.ones(3)
582+
assert_raises(TypeError, np.add, p, x)
583+
assert_raises(TypeError, np.add, x, p)
584+
585+
578586
if __name__ == "__main__":
579587
run_module_suite()

0 commit comments

Comments
 (0)
0