8000 ENH: Use `__array_ufunc__ = None` in polynomial convenience classes. by charris · Pull Request #9015 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Use __array_ufunc__ = None in polynomial convenience classes. #9015

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

Merged
merged 2 commits into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions doc/release/1.13.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions numpy/polynomial/_polybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions numpy/polynomial/tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


#
Expand Down Expand Up @@ -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()
0