summaryrefslogtreecommitdiff
path: root/numpy/polynomial/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial/tests')
-rw-r--r--numpy/polynomial/tests/test_chebyshev.py38
-rw-r--r--numpy/polynomial/tests/test_classes.py11
-rw-r--r--numpy/polynomial/tests/test_hermite.py34
-rw-r--r--numpy/polynomial/tests/test_hermite_e.py34
-rw-r--r--numpy/polynomial/tests/test_laguerre.py34
-rw-r--r--numpy/polynomial/tests/test_legendre.py34
-rw-r--r--numpy/polynomial/tests/test_polynomial.py36
-rw-r--r--numpy/polynomial/tests/test_polyutils.py6
-rw-r--r--numpy/polynomial/tests/test_printing.py6
9 files changed, 108 insertions, 125 deletions
diff --git a/numpy/polynomial/tests/test_chebyshev.py b/numpy/polynomial/tests/test_chebyshev.py
index c8d2d6dba..2f54bebfd 100644
--- a/numpy/polynomial/tests/test_chebyshev.py
+++ b/numpy/polynomial/tests/test_chebyshev.py
@@ -1,8 +1,6 @@
"""Tests for chebyshev module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
@@ -30,7 +28,7 @@ T9 = [0, 9, 0, -120, 0, 432, 0, -576, 0, 256]
Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
-class TestPrivate(object):
+class TestPrivate:
def test__cseries_to_zseries(self):
for i in range(5):
@@ -47,7 +45,7 @@ class TestPrivate(object):
assert_equal(res, tgt)
-class TestConstants(object):
+class TestConstants:
def test_chebdomain(self):
assert_equal(cheb.chebdomain, [-1, 1])
@@ -62,12 +60,12 @@ class TestConstants(object):
assert_equal(cheb.chebx, [0, 1])
-class TestArithmetic(object):
+class TestArithmetic:
def test_chebadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -77,7 +75,7 @@ class TestArithmetic(object):
def test_chebsub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -95,7 +93,7 @@ class TestArithmetic(object):
def test_chebmul(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(i + j + 1)
tgt[i + j] += .5
tgt[abs(i - j)] += .5
@@ -105,7 +103,7 @@ class TestArithmetic(object):
def test_chebdiv(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1]
cj = [0]*j + [1]
tgt = cheb.chebadd(ci, cj)
@@ -116,14 +114,14 @@ class TestArithmetic(object):
def test_chebpow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(cheb.chebmul, [c]*j, np.array([1]))
res = cheb.chebpow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([2.5, 2., 1.5])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -141,7 +139,7 @@ class TestEvaluation(object):
x = np.linspace(-1, 1)
y = [polyval(x, c) for c in Tlist]
for i in range(10):
- msg = "At i=%d" % i
+ msg = f"At i={i}"
tgt = y[i]
res = cheb.chebval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -217,7 +215,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_chebint(self):
# check exceptions
@@ -319,7 +317,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_chebder(self):
# check exceptions
@@ -359,7 +357,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -407,7 +405,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestFitting(object):
+class TestFitting:
def test_chebfit(self):
def f(x):
@@ -484,7 +482,7 @@ class TestFitting(object):
assert_almost_equal(coef1, coef2)
-class TestInterpolate(object):
+class TestInterpolate:
def f(self, x):
return x * (x - 1) * (x - 2)
@@ -509,7 +507,7 @@ class TestInterpolate(object):
assert_almost_equal(cheb.chebval(x, c), powx(x, p), decimal=12)
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, cheb.chebcompanion, [])
@@ -524,7 +522,7 @@ class TestCompanion(object):
assert_(cheb.chebcompanion([1, 2])[0, 0] == -.5)
-class TestGauss(object):
+class TestGauss:
def test_100(self):
x, w = cheb.chebgauss(100)
@@ -543,7 +541,7 @@ class TestGauss(object):
assert_almost_equal(w.sum(), tgt)
-class TestMisc(object):
+class TestMisc:
def test_chebfromroots(self):
res = cheb.chebfromroots([])
diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py
index 2261f960b..e9f256cf8 100644
--- a/numpy/polynomial/tests/test_classes.py
+++ b/numpy/polynomial/tests/test_classes.py
@@ -3,8 +3,6 @@
This tests the convert and cast methods of all the polynomial classes.
"""
-from __future__ import division, absolute_import, print_function
-
import operator as op
from numbers import Number
@@ -15,7 +13,6 @@ from numpy.polynomial import (
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
)
-from numpy.compat import long
from numpy.polynomial.polyutils import RankWarning
#
@@ -44,7 +41,7 @@ def assert_poly_almost_equal(p1, p2, msg=""):
assert_(np.all(p1.window == p2.window))
assert_almost_equal(p1.coef, p2.coef)
except AssertionError:
- msg = "Result: %s\nTarget: %s", (p1, p2)
+ msg = f"Result: {p1}\nTarget: {p2}"
raise AssertionError(msg)
@@ -317,7 +314,7 @@ def test_truediv(Poly):
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
- for stype in (int, long, float):
+ for stype in (int, float):
s = stype(5)
assert_poly_almost_equal(op.truediv(p2, s), p1)
assert_raises(TypeError, op.truediv, s, p2)
@@ -574,7 +571,7 @@ def test_ufunc_override(Poly):
-class TestLatexRepr(object):
+class TestLatexRepr:
"""Test the latex repr used by ipython """
def as_latex(self, obj):
@@ -628,7 +625,7 @@ class TestLatexRepr(object):
#
-class TestInterpolate(object):
+class TestInterpolate:
def f(self, x):
return x * (x - 1) * (x - 2)
diff --git a/numpy/polynomial/tests/test_hermite.py b/numpy/polynomial/tests/test_hermite.py
index 271c1964b..53ee0844e 100644
--- a/numpy/polynomial/tests/test_hermite.py
+++ b/numpy/polynomial/tests/test_hermite.py
@@ -1,8 +1,6 @@
"""Tests for hermite module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
@@ -30,7 +28,7 @@ def trim(x):
return herm.hermtrim(x, tol=1e-6)
-class TestConstants(object):
+class TestConstants:
def test_hermdomain(self):
assert_equal(herm.hermdomain, [-1, 1])
@@ -45,13 +43,13 @@ class TestConstants(object):
assert_equal(herm.hermx, [0, .5])
-class TestArithmetic(object):
+class TestArithmetic:
x = np.linspace(-3, 3, 100)
def test_hermadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -61,7 +59,7 @@ class TestArithmetic(object):
def test_hermsub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -82,7 +80,7 @@ class TestArithmetic(object):
pol1 = [0]*i + [1]
val1 = herm.hermval(self.x, pol1)
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
pol2 = [0]*j + [1]
val2 = herm.hermval(self.x, pol2)
pol3 = herm.hermmul(pol1, pol2)
@@ -93,7 +91,7 @@ class TestArithmetic(object):
def test_hermdiv(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1]
cj = [0]*j + [1]
tgt = herm.hermadd(ci, cj)
@@ -104,14 +102,14 @@ class TestArithmetic(object):
def test_hermpow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(herm.hermmul, [c]*j, np.array([1]))
res = herm.hermpow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([2.5, 1., .75])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -129,7 +127,7 @@ class TestEvaluation(object):
x = np.linspace(-1, 1)
y = [polyval(x, c) for c in Hlist]
for i in range(10):
- msg = "At i=%d" % i
+ msg = f"At i={i}"
tgt = y[i]
res = herm.hermval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -205,7 +203,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_hermint(self):
# check exceptions
@@ -307,7 +305,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_hermder(self):
# check exceptions
@@ -347,7 +345,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -395,7 +393,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestFitting(object):
+class TestFitting:
def test_hermfit(self):
def f(x):
@@ -472,7 +470,7 @@ class TestFitting(object):
assert_almost_equal(coef1, coef2)
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, herm.hermcompanion, [])
@@ -487,7 +485,7 @@ class TestCompanion(object):
assert_(herm.hermcompanion([1, 2])[0, 0] == -.25)
-class TestGauss(object):
+class TestGauss:
def test_100(self):
x, w = herm.hermgauss(100)
@@ -506,7 +504,7 @@ class TestGauss(object):
assert_almost_equal(w.sum(), tgt)
-class TestMisc(object):
+class TestMisc:
def test_hermfromroots(self):
res = herm.hermfromroots([])
diff --git a/numpy/polynomial/tests/test_hermite_e.py b/numpy/polynomial/tests/test_hermite_e.py
index 434b30e7b..2d262a330 100644
--- a/numpy/polynomial/tests/test_hermite_e.py
+++ b/numpy/polynomial/tests/test_hermite_e.py
@@ -1,8 +1,6 @@
"""Tests for hermite_e module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
@@ -30,7 +28,7 @@ def trim(x):
return herme.hermetrim(x, tol=1e-6)
-class TestConstants(object):
+class TestConstants:
def test_hermedomain(self):
assert_equal(herme.hermedomain, [-1, 1])
@@ -45,13 +43,13 @@ class TestConstants(object):
assert_equal(herme.hermex, [0, 1])
-class TestArithmetic(object):
+class TestArithmetic:
x = np.linspace(-3, 3, 100)
def test_hermeadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -61,7 +59,7 @@ class TestArithmetic(object):
def test_hermesub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -82,7 +80,7 @@ class TestArithmetic(object):
pol1 = [0]*i + [1]
val1 = herme.hermeval(self.x, pol1)
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
pol2 = [0]*j + [1]
val2 = herme.hermeval(self.x, pol2)
pol3 = herme.hermemul(pol1, pol2)
@@ -93,7 +91,7 @@ class TestArithmetic(object):
def test_hermediv(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1]
cj = [0]*j + [1]
tgt = herme.hermeadd(ci, cj)
@@ -104,14 +102,14 @@ class TestArithmetic(object):
def test_hermepow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(herme.hermemul, [c]*j, np.array([1]))
res = herme.hermepow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([4., 2., 3.])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -129,7 +127,7 @@ class TestEvaluation(object):
x = np.linspace(-1, 1)
y = [polyval(x, c) for c in Helist]
for i in range(10):
- msg = "At i=%d" % i
+ msg = f"At i={i}"
tgt = y[i]
res = herme.hermeval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -205,7 +203,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_hermeint(self):
# check exceptions
@@ -307,7 +305,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_hermeder(self):
# check exceptions
@@ -348,7 +346,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -396,7 +394,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestFitting(object):
+class TestFitting:
def test_hermefit(self):
def f(x):
@@ -473,7 +471,7 @@ class TestFitting(object):
assert_almost_equal(coef1, coef2)
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, herme.hermecompanion, [])
@@ -488,7 +486,7 @@ class TestCompanion(object):
assert_(herme.hermecompanion([1, 2])[0, 0] == -.5)
-class TestGauss(object):
+class TestGauss:
def test_100(self):
x, w = herme.hermegauss(100)
@@ -507,7 +505,7 @@ class TestGauss(object):
assert_almost_equal(w.sum(), tgt)
-class TestMisc(object):
+class TestMisc:
def test_hermefromroots(self):
res = herme.hermefromroots([])
diff --git a/numpy/polynomial/tests/test_laguerre.py b/numpy/polynomial/tests/test_laguerre.py
index 4b9b28637..227ef3c55 100644
--- a/numpy/polynomial/tests/test_laguerre.py
+++ b/numpy/polynomial/tests/test_laguerre.py
@@ -1,8 +1,6 @@
"""Tests for laguerre module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
@@ -27,7 +25,7 @@ def trim(x):
return lag.lagtrim(x, tol=1e-6)
-class TestConstants(object):
+class TestConstants:
def test_lagdomain(self):
assert_equal(lag.lagdomain, [0, 1])
@@ -42,13 +40,13 @@ class TestConstants(object):
assert_equal(lag.lagx, [1, -1])
-class TestArithmetic(object):
+class TestArithmetic:
x = np.linspace(-3, 3, 100)
def test_lagadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -58,7 +56,7 @@ class TestArithmetic(object):
def test_lagsub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -79,7 +77,7 @@ class TestArithmetic(object):
pol1 = [0]*i + [1]
val1 = lag.lagval(self.x, pol1)
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
pol2 = [0]*j + [1]
val2 = lag.lagval(self.x, pol2)
pol3 = lag.lagmul(pol1, pol2)
@@ -90,7 +88,7 @@ class TestArithmetic(object):
def test_lagdiv(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1]
cj = [0]*j + [1]
tgt = lag.lagadd(ci, cj)
@@ -101,14 +99,14 @@ class TestArithmetic(object):
def test_lagpow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(lag.lagmul, [c]*j, np.array([1]))
res = lag.lagpow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([9., -14., 6.])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -126,7 +124,7 @@ class TestEvaluation(object):
x = np.linspace(-1, 1)
y = [polyval(x, c) for c in Llist]
for i in range(7):
- msg = "At i=%d" % i
+ msg = f"At i={i}"
tgt = y[i]
res = lag.lagval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -202,7 +200,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_lagint(self):
# check exceptions
@@ -304,7 +302,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_lagder(self):
# check exceptions
@@ -344,7 +342,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -392,7 +390,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestFitting(object):
+class TestFitting:
def test_lagfit(self):
def f(x):
@@ -454,7 +452,7 @@ class TestFitting(object):
assert_almost_equal(lag.lagfit(x, x, [0, 1]), [1, -1])
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, lag.lagcompanion, [])
@@ -469,7 +467,7 @@ class TestCompanion(object):
assert_(lag.lagcompanion([1, 2])[0, 0] == 1.5)
-class TestGauss(object):
+class TestGauss:
def test_100(self):
x, w = lag.laggauss(100)
@@ -488,7 +486,7 @@ class TestGauss(object):
assert_almost_equal(w.sum(), tgt)
-class TestMisc(object):
+class TestMisc:
def test_lagfromroots(self):
res = lag.lagfromroots([])
diff --git a/numpy/polynomial/tests/test_legendre.py b/numpy/polynomial/tests/test_legendre.py
index 917a7e03a..a2a212c24 100644
--- a/numpy/polynomial/tests/test_legendre.py
+++ b/numpy/polynomial/tests/test_legendre.py
@@ -1,8 +1,6 @@
"""Tests for legendre module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
@@ -30,7 +28,7 @@ def trim(x):
return leg.legtrim(x, tol=1e-6)
-class TestConstants(object):
+class TestConstants:
def test_legdomain(self):
assert_equal(leg.legdomain, [-1, 1])
@@ -45,13 +43,13 @@ class TestConstants(object):
assert_equal(leg.legx, [0, 1])
-class TestArithmetic(object):
+class TestArithmetic:
x = np.linspace(-1, 1, 100)
def test_legadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -61,7 +59,7 @@ class TestArithmetic(object):
def test_legsub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -83,7 +81,7 @@ class TestArithmetic(object):
pol1 = [0]*i + [1]
val1 = leg.legval(self.x, pol1)
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
pol2 = [0]*j + [1]
val2 = leg.legval(self.x, pol2)
pol3 = leg.legmul(pol1, pol2)
@@ -94,7 +92,7 @@ class TestArithmetic(object):
def test_legdiv(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1]
cj = [0]*j + [1]
tgt = leg.legadd(ci, cj)
@@ -105,14 +103,14 @@ class TestArithmetic(object):
def test_legpow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(leg.legmul, [c]*j, np.array([1]))
res = leg.legpow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([2., 2., 2.])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -130,7 +128,7 @@ class TestEvaluation(object):
x = np.linspace(-1, 1)
y = [polyval(x, c) for c in Llist]
for i in range(10):
- msg = "At i=%d" % i
+ msg = f"At i={i}"
tgt = y[i]
res = leg.legval(x, [0]*i + [1])
assert_almost_equal(res, tgt, err_msg=msg)
@@ -206,7 +204,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_legint(self):
# check exceptions
@@ -308,7 +306,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_legder(self):
# check exceptions
@@ -348,7 +346,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -396,7 +394,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestFitting(object):
+class TestFitting:
def test_legfit(self):
def f(x):
@@ -473,7 +471,7 @@ class TestFitting(object):
assert_almost_equal(coef1, coef2)
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, leg.legcompanion, [])
@@ -488,7 +486,7 @@ class TestCompanion(object):
assert_(leg.legcompanion([1, 2])[0, 0] == -.5)
-class TestGauss(object):
+class TestGauss:
def test_100(self):
x, w = leg.leggauss(100)
@@ -507,7 +505,7 @@ class TestGauss(object):
assert_almost_equal(w.sum(), tgt)
-class TestMisc(object):
+class TestMisc:
def test_legfromroots(self):
res = leg.legfromroots([])
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py
index 1436963c6..5fd1a82a2 100644
--- a/numpy/polynomial/tests/test_polynomial.py
+++ b/numpy/polynomial/tests/test_polynomial.py
@@ -1,15 +1,13 @@
"""Tests for polynomial module.
"""
-from __future__ import division, absolute_import, print_function
-
from functools import reduce
import numpy as np
import numpy.polynomial.polynomial as poly
from numpy.testing import (
assert_almost_equal, assert_raises, assert_equal, assert_,
- assert_warns, assert_array_equal)
+ assert_warns, assert_array_equal, assert_raises_regex)
def trim(x):
@@ -29,7 +27,7 @@ T9 = [0, 9, 0, -120, 0, 432, 0, -576, 0, 256]
Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9]
-class TestConstants(object):
+class TestConstants:
def test_polydomain(self):
assert_equal(poly.polydomain, [-1, 1])
@@ -44,12 +42,12 @@ class TestConstants(object):
assert_equal(poly.polyx, [0, 1])
-class TestArithmetic(object):
+class TestArithmetic:
def test_polyadd(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] += 1
@@ -59,7 +57,7 @@ class TestArithmetic(object):
def test_polysub(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(max(i, j) + 1)
tgt[i] += 1
tgt[j] -= 1
@@ -77,7 +75,7 @@ class TestArithmetic(object):
def test_polymul(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
tgt = np.zeros(i + j + 1)
tgt[i + j] += 1
res = poly.polymul([0]*i + [1], [0]*j + [1])
@@ -96,7 +94,7 @@ class TestArithmetic(object):
# check rest.
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
ci = [0]*i + [1, 2]
cj = [0]*j + [1, 2]
tgt = poly.polyadd(ci, cj)
@@ -107,14 +105,14 @@ class TestArithmetic(object):
def test_polypow(self):
for i in range(5):
for j in range(5):
- msg = "At i=%d, j=%d" % (i, j)
+ msg = f"At i={i}, j={j}"
c = np.arange(i + 1)
tgt = reduce(poly.polymul, [c]*j, np.array([1]))
res = poly.polypow(c, j)
assert_equal(trim(res), trim(tgt), err_msg=msg)
-class TestEvaluation(object):
+class TestEvaluation:
# coefficients of 1 + 2*x + 3*x**2
c1d = np.array([1., 2., 3.])
c2d = np.einsum('i,j->ij', c1d, c1d)
@@ -229,7 +227,8 @@ class TestEvaluation(object):
y1, y2, y3 = self.y
#test exceptions
- assert_raises(ValueError, poly.polyval2d, x1, x2[:2], self.c2d)
+ assert_raises_regex(ValueError, 'incompatible',
+ poly.polyval2d, x1, x2[:2], self.c2d)
#test values
tgt = y1*y2
@@ -246,7 +245,8 @@ class TestEvaluation(object):
y1, y2, y3 = self.y
#test exceptions
- assert_raises(ValueError, poly.polyval3d, x1, x2, x3[:2], self.c3d)
+ assert_raises_regex(ValueError, 'incompatible',
+ poly.polyval3d, x1, x2, x3[:2], self.c3d)
#test values
tgt = y1*y2*y3
@@ -287,7 +287,7 @@ class TestEvaluation(object):
assert_(res.shape == (2, 3)*3)
-class TestIntegral(object):
+class TestIntegral:
def test_polyint(self):
# check exceptions
@@ -386,7 +386,7 @@ class TestIntegral(object):
assert_almost_equal(res, tgt)
-class TestDerivative(object):
+class TestDerivative:
def test_polyder(self):
# check exceptions
@@ -426,7 +426,7 @@ class TestDerivative(object):
assert_almost_equal(res, tgt)
-class TestVander(object):
+class TestVander:
# some random values in [-1, 1)
x = np.random.random((3, 5))*2 - 1
@@ -474,7 +474,7 @@ class TestVander(object):
assert_(van.shape == (1, 5, 24))
-class TestCompanion(object):
+class TestCompanion:
def test_raises(self):
assert_raises(ValueError, poly.polycompanion, [])
@@ -489,7 +489,7 @@ class TestCompanion(object):
assert_(poly.polycompanion([1, 2])[0, 0] == -.5)
-class TestMisc(object):
+class TestMisc:
def test_polyfromroots(self):
res = poly.polyfromroots([])
diff --git a/numpy/polynomial/tests/test_polyutils.py b/numpy/polynomial/tests/test_polyutils.py
index 801c558cc..1b27f53b5 100644
--- a/numpy/polynomial/tests/test_polyutils.py
+++ b/numpy/polynomial/tests/test_polyutils.py
@@ -1,8 +1,6 @@
"""Tests for polyutils module.
"""
-from __future__ import division, absolute_import, print_function
-
import numpy as np
import numpy.polynomial.polyutils as pu
from numpy.testing import (
@@ -10,7 +8,7 @@ from numpy.testing import (
)
-class TestMisc(object):
+class TestMisc:
def test_trimseq(self):
for i in range(5):
@@ -43,7 +41,7 @@ class TestMisc(object):
assert_equal(pu.trimcoef(coef, 2), [0])
-class TestDomain(object):
+class TestDomain:
def test_getdomain(self):
# test for real values
diff --git a/numpy/polynomial/tests/test_printing.py b/numpy/polynomial/tests/test_printing.py
index 3f1236402..049d3af2f 100644
--- a/numpy/polynomial/tests/test_printing.py
+++ b/numpy/polynomial/tests/test_printing.py
@@ -1,10 +1,8 @@
-from __future__ import division, absolute_import, print_function
-
import numpy.polynomial as poly
from numpy.testing import assert_equal
-class TestStr(object):
+class TestStr:
def test_polynomial_str(self):
res = str(poly.Polynomial([0, 1]))
tgt = 'poly([0. 1.])'
@@ -36,7 +34,7 @@ class TestStr(object):
assert_equal(res, tgt)
-class TestRepr(object):
+class TestRepr:
def test_polynomial_str(self):
res = repr(poly.Polynomial([0, 1]))
tgt = 'Polynomial([0., 1.], domain=[-1, 1], window=[-1, 1])'