8000 Merge pull request #10142 from mhvk/pending-deprecation-for-matrix · numpy/numpy@6721890 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6721890

Browse files
authored
Merge pull request #10142 from mhvk/pending-deprecation-for-matrix
DEP: Pending deprecation warning for matrix
2 parents 10b56ff + 86f487c commit 6721890

File tree

9 files changed

+75
-0
lines changed

9 files changed

+75
-0
lines changed

numpy/matrixlib/defmatrix.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__all__ = ['matrix', 'bmat', 'mat', 'asmatrix']
44

55
import sys
6+
import warnings
67
import ast
78
import numpy.core.numeric as N
89
from numpy.core.numeric import concatenate, isscalar
@@ -70,6 +71,10 @@ class matrix(N.ndarray):
7071
"""
7172
matrix(data, dtype=None, copy=True)
7273
74+
.. note:: It is no longer recommended to use this class, even for linear
75+
algebra. Instead use regular arrays. The class may be removed
76+
in the future.
77+
7378
Returns a matrix from an array-like object, or from a string of data.
7479
A matrix is a specialized 2-D array that retains its 2-D nature
7580
through operations. It has certain special operators, such as ``*``
@@ -105,6 +110,12 @@ class matrix(N.ndarray):
105110
"""
106111
__array_priority__ = 10.0
107112
def __new__(subtype, data, dtype=None, copy=True):
113+
warnings.warn('the matrix subclass is not the recommended way to '
114+
'represent matrices or deal with linear algebra (see '
115+
'https://docs.scipy.org/doc/numpy/user/'
116+
'numpy-for-matlab-users.html). '
117+
'Please adjust your code to use regular ndarray.',
118+
PendingDeprecationWarning, stacklevel=2)
108119
if isinstance(data, matrix):
109120
dtype2 = data.dtype
110121
if (dtype is None):

numpy/matrixlib/tests/test_defmatrix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
try:
412
# Accessing collections abstract classes from collections
513
# has been deprecated since Python 3.3

numpy/matrixlib/tests/test_interaction.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
"""
55
from __future__ import division, absolute_import, print_function
66

7+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
8+
try:
9+
import pytest
10+
pytestmark = pytest.mark.filterwarnings(
11+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
12+
except ImportError:
13+
pass
14+
715
import textwrap
816
import warnings
917

numpy/matrixlib/tests/test_masked_matrix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
import pickle
412

513
import numpy as np

numpy/matrixlib/tests/test_matrix_linalg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
""" Test functions for linalg module using the matrix class."""
22
from __future__ import division, absolute_import, print_function
33

4+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
5+
try:
6+
import pytest
7+
pytestmark = pytest.mark.filterwarnings(
8+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
9+
except ImportError:
10+
pass
11+
412
import numpy as np
513

614
from numpy.linalg.tests.test_linalg import (

numpy/matrixlib/tests/test_multiarray.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
import numpy as np
412
from numpy.testing import assert_, assert_equal, assert_array_equal
513

numpy/matrixlib/tests/test_numeric.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
import numpy as np
412
from numpy.testing import assert_equal
513

numpy/matrixlib/tests/test_regression.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
import numpy as np
412
from numpy.testing import assert_, assert_equal, assert_raises
513

numpy/tests/test_matlib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from __future__ import division, absolute_import, print_function
22

3+
# As we are testing matrices, we ignore its PendingDeprecationWarnings
4+
try:
5+
import pytest
6+
pytestmark = pytest.mark.filterwarnings(
7+
'ignore:the matrix subclass is not:PendingDeprecationWarning')
8+
except ImportError:
9+
pass
10+
311
import numpy as np
412
import numpy.matlib
513
from numpy.testing import assert_array_equal, assert_

0 commit comments

Comments
 (0)
0