diff options
Diffstat (limited to 'numpy/matrixlib')
-rw-r--r-- | numpy/matrixlib/__init__.py | 2 | ||||
-rw-r--r-- | numpy/matrixlib/defmatrix.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/setup.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_defmatrix.py | 29 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_interaction.py | 31 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_masked_matrix.py | 8 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_matrix_linalg.py | 2 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_multiarray.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_numeric.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_regression.py | 4 |
10 files changed, 30 insertions, 62 deletions
diff --git a/numpy/matrixlib/__init__.py b/numpy/matrixlib/__init__.py index 777e0cd33..54154d11f 100644 --- a/numpy/matrixlib/__init__.py +++ b/numpy/matrixlib/__init__.py @@ -1,8 +1,6 @@ """Sub-package containing the matrix class and related functions. """ -from __future__ import division, absolute_import, print_function - from .defmatrix import * __all__ = defmatrix.__all__ diff --git a/numpy/matrixlib/defmatrix.py b/numpy/matrixlib/defmatrix.py index 3c7e8ffc2..12ac74cb2 100644 --- a/numpy/matrixlib/defmatrix.py +++ b/numpy/matrixlib/defmatrix.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - __all__ = ['matrix', 'bmat', 'mat', 'asmatrix'] import sys @@ -1046,7 +1044,7 @@ def bmat(obj, ldict=None, gdict=None): referenced by name. ldict : dict, optional A dictionary that replaces local operands in current frame. - Ignored if `obj` is not a string or `gdict` is `None`. + Ignored if `obj` is not a string or `gdict` is None. gdict : dict, optional A dictionary that replaces global operands in current frame. Ignored if `obj` is not a string. diff --git a/numpy/matrixlib/setup.py b/numpy/matrixlib/setup.py index d0981d658..529d2a2eb 100644 --- a/numpy/matrixlib/setup.py +++ b/numpy/matrixlib/setup.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python -from __future__ import division, print_function - +#!/usr/bin/env python3 def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('matrixlib', parent_package, top_path) diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py index aa6e08d64..4cb5f3a37 100644 --- a/numpy/matrixlib/tests/test_defmatrix.py +++ b/numpy/matrixlib/tests/test_defmatrix.py @@ -1,11 +1,4 @@ -from __future__ import division, absolute_import, print_function - -try: - # Accessing collections abstract classes from collections - # has been deprecated since Python 3.3 - import collections.abc as collections_abc -except ImportError: - import collections as collections_abc +import collections.abc import numpy as np from numpy import matrix, asmatrix, bmat @@ -16,7 +9,7 @@ from numpy.testing import ( from numpy.linalg import matrix_power from numpy.matrixlib import mat -class TestCtor(object): +class TestCtor: def test_basic(self): A = np.array([[1, 2], [3, 4]]) mA = matrix(A) @@ -63,7 +56,7 @@ class TestCtor(object): assert_(np.all(b2 == mixresult)) -class TestProperties(object): +class TestProperties: def test_sum(self): """Test whether matrix.sum(axis=1) preserves orientation. Fails in NumPy <= 0.9.6.2127. @@ -196,7 +189,7 @@ class TestProperties(object): B = matrix([[True], [True], [False]]) assert_array_equal(A, B) -class TestCasting(object): +class TestCasting: def test_basic(self): A = np.arange(100).reshape(10, 10) mA = matrix(A) @@ -215,7 +208,7 @@ class TestCasting(object): assert_(np.all(mA != mB)) -class TestAlgebra(object): +class TestAlgebra: def test_basic(self): import numpy.linalg as linalg @@ -274,7 +267,7 @@ class TestAlgebra(object): A*object() -class TestMatrixReturn(object): +class TestMatrixReturn: def test_instance_methods(self): a = matrix([1.0], dtype='f8') methodargs = { @@ -299,7 +292,7 @@ class TestMatrixReturn(object): if attrib.startswith('_') or attrib in excluded_methods: continue f = getattr(a, attrib) - if isinstance(f, collections_abc.Callable): + if isinstance(f, collections.abc.Callable): # reset contents of a a.astype('f8') a.fill(1.0) @@ -316,7 +309,7 @@ class TestMatrixReturn(object): assert_(type(d) is np.ndarray) -class TestIndexing(object): +class TestIndexing: def test_basic(self): x = asmatrix(np.zeros((3, 2), float)) y = np.zeros((3, 1), float) @@ -325,7 +318,7 @@ class TestIndexing(object): assert_equal(x, [[0, 1], [0, 0], [0, 0]]) -class TestNewScalarIndexing(object): +class TestNewScalarIndexing: a = matrix([[1, 2], [3, 4]]) def test_dimesions(self): @@ -392,7 +385,7 @@ class TestNewScalarIndexing(object): assert_array_equal(x[[2, 1, 0],:], x[::-1,:]) -class TestPower(object): +class TestPower: def test_returntype(self): a = np.array([[0, 1], [0, 0]]) assert_(type(matrix_power(a, 2)) is np.ndarray) @@ -403,7 +396,7 @@ class TestPower(object): assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]]) -class TestShape(object): +class TestShape: a = np.array([[1], [2]]) m = matrix([[1], [2]]) diff --git a/numpy/matrixlib/tests/test_interaction.py b/numpy/matrixlib/tests/test_interaction.py index 088ae3c6a..5154bd621 100644 --- a/numpy/matrixlib/tests/test_interaction.py +++ b/numpy/matrixlib/tests/test_interaction.py @@ -2,8 +2,6 @@ Note that tests with MaskedArray and linalg are done in separate files. """ -from __future__ import division, absolute_import, print_function - import pytest import textwrap @@ -290,7 +288,7 @@ def test_kron_matrix(): assert_equal(type(np.kron(m, a)), np.matrix) -class TestConcatenatorMatrix(object): +class TestConcatenatorMatrix: # 2018-04-29: moved here from core.tests.test_index_tricks. def test_matrix(self): a = [1, 2] @@ -326,24 +324,17 @@ class TestConcatenatorMatrix(object): def test_array_equal_error_message_matrix(): # 2018-04-29: moved here from testing.tests.test_utils. - try: + with pytest.raises(AssertionError) as exc_info: assert_equal(np.array([1, 2]), np.matrix([1, 2])) - except AssertionError as e: - msg = str(e) - msg2 = msg.replace("shapes (2L,), (1L, 2L)", "shapes (2,), (1, 2)") - msg_reference = textwrap.dedent("""\ - - Arrays are not equal - - (shapes (2,), (1, 2) mismatch) - x: array([1, 2]) - y: matrix([[1, 2]])""") - try: - assert_equal(msg, msg_reference) - except AssertionError: - assert_equal(msg2, msg_reference) - else: - raise AssertionError("Did not raise") + msg = str(exc_info.value) + msg_reference = textwrap.dedent("""\ + + Arrays are not equal + + (shapes (2,), (1, 2) mismatch) + x: array([1, 2]) + y: matrix([[1, 2]])""") + assert_equal(msg, msg_reference) def test_array_almost_equal_matrix(): diff --git a/numpy/matrixlib/tests/test_masked_matrix.py b/numpy/matrixlib/tests/test_masked_matrix.py index d3911d2e1..45424ecf0 100644 --- a/numpy/matrixlib/tests/test_masked_matrix.py +++ b/numpy/matrixlib/tests/test_masked_matrix.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.ma.testutils import (assert_, assert_equal, assert_raises, assert_array_equal) @@ -29,7 +27,7 @@ class MMatrix(MaskedArray, np.matrix,): return _view -class TestMaskedMatrix(object): +class TestMaskedMatrix: def test_matrix_indexing(self): # Tests conversions and indexing x1 = np.matrix([[1, 2, 3], [4, 3, 2]]) @@ -171,7 +169,7 @@ class TestMaskedMatrix(object): assert_(not isinstance(test, MaskedArray)) -class TestSubclassing(object): +class TestSubclassing: # Test suite for masked subclasses of ndarray. def setup(self): @@ -212,7 +210,7 @@ class TestSubclassing(object): assert_(isinstance(divide(mx, x), MMatrix)) assert_equal(divide(mx, mx), divide(xmx, xmx)) -class TestConcatenator(object): +class TestConcatenator: # Tests for mr_, the equivalent of r_ for masked arrays. def test_matrix_builder(self): diff --git a/numpy/matrixlib/tests/test_matrix_linalg.py b/numpy/matrixlib/tests/test_matrix_linalg.py index 6fc733c2e..106c2e382 100644 --- a/numpy/matrixlib/tests/test_matrix_linalg.py +++ b/numpy/matrixlib/tests/test_matrix_linalg.py @@ -1,6 +1,4 @@ """ Test functions for linalg module using the matrix class.""" -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.linalg.tests.test_linalg import ( diff --git a/numpy/matrixlib/tests/test_multiarray.py b/numpy/matrixlib/tests/test_multiarray.py index 6d84bd477..638d0d153 100644 --- a/numpy/matrixlib/tests/test_multiarray.py +++ b/numpy/matrixlib/tests/test_multiarray.py @@ -1,9 +1,7 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import assert_, assert_equal, assert_array_equal -class TestView(object): +class TestView: def test_type(self): x = np.array([1, 2, 3]) assert_(isinstance(x.view(np.matrix), np.matrix)) diff --git a/numpy/matrixlib/tests/test_numeric.py b/numpy/matrixlib/tests/test_numeric.py index 95e1c8001..a772bb388 100644 --- a/numpy/matrixlib/tests/test_numeric.py +++ b/numpy/matrixlib/tests/test_numeric.py @@ -1,9 +1,7 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import assert_equal -class TestDot(object): +class TestDot: def test_matscalar(self): b1 = np.matrix(np.ones((3, 3), dtype=complex)) assert_equal(b1*1.0, b1) diff --git a/numpy/matrixlib/tests/test_regression.py b/numpy/matrixlib/tests/test_regression.py index 70e147279..a54d44020 100644 --- a/numpy/matrixlib/tests/test_regression.py +++ b/numpy/matrixlib/tests/test_regression.py @@ -1,10 +1,8 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from numpy.testing import assert_, assert_equal, assert_raises -class TestRegression(object): +class TestRegression: def test_kron_matrix(self): # Ticket #71 x = np.matrix('[1 0; 1 0]') |