summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-03-09 02:57:18 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-03-09 02:57:18 +0000
commit18b7cd9df7a4d960550b18faa14d5473e7d5c3d9 (patch)
treea6e1cbeda9b501c2b29121c0b9ca9fa94c95b4bf /numpy/lib
parent6a3edf3210b439a4d1a51acb4e01bac017697ee6 (diff)
downloadpython-numpy-18b7cd9df7a4d960550b18faa14d5473e7d5c3d9.tar.gz
python-numpy-18b7cd9df7a4d960550b18faa14d5473e7d5c3d9.tar.bz2
python-numpy-18b7cd9df7a4d960550b18faa14d5473e7d5c3d9.zip
BUG: Prevent crash in poly1d.__eq__
Fixes #8760
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/polynomial.py4
-rw-r--r--numpy/lib/tests/test_polynomial.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index f00d95b6c..6c0c11ac6 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -1199,11 +1199,15 @@ class poly1d(object):
__rtruediv__ = __rdiv__
def __eq__(self, other):
+ if not isinstance(other, poly1d):
+ return NotImplemented
if self.coeffs.shape != other.coeffs.shape:
return False
return (self.coeffs == other.coeffs).all()
def __ne__(self, other):
+ if not isinstance(other, poly1d):
+ return NotImplemented
return not self.__eq__(other)
def __setattr__(self, key, val):
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 00dffd3d3..f1e4543bb 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -213,6 +213,15 @@ class TestDocs(TestCase):
v = np.arange(1, 21)
assert_almost_equal(np.poly(v), np.poly(np.diag(v)))
+ def test_poly_eq(self):
+ p = np.poly1d([1, 2, 3])
+ p2 = np.poly1d([1, 2, 4])
+ assert_equal(p == None, False)
+ assert_equal(p != None, True)
+ assert_equal(p == p, True)
+ assert_equal(p == p2, False)
+ assert_equal(p != p2, True)
+
if __name__ == "__main__":
run_module_suite()