Skip to content
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

DEP: Pending deprecation warning for matrix #10142

Merged
merged 2 commits into from May 30, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions numpy/matrixlib/defmatrix.py
Expand Up @@ -3,6 +3,7 @@
__all__ = ['matrix', 'bmat', 'mat', 'asmatrix']

import sys
import warnings
import ast
import numpy.core.numeric as N
from numpy.core.numeric import concatenate, isscalar
Expand Down Expand Up @@ -70,6 +71,10 @@ class matrix(N.ndarray):
"""
matrix(data, dtype=None, copy=True)

.. note:: It is no longer recommended to use this class, even for linear
algebra. Instead use regular arrays. The class may be removed
in the future.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to get this message into 1.15?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, early enough to deal with the potential fallout in any case. If we follow @rgommers suggestion, latest NumPy will require latest SciPy. We could hold off until the next SciPy release, we are doing that with some f2py changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean #10142 (comment), then I don't think it does (at least, it doesn't matter how the PendingDeprecationWarning is silenced). PendingDeprecationWarnings also won't show up for normal users, only if you run with -Wd or raise exceptions on warnings or something like that.

+1 for getting this note into 1.15


Returns a matrix from an array-like object, or from a string of data.
A matrix is a specialized 2-D array that retains its 2-D nature
through operations. It has certain special operators, such as ``*``
Expand Down Expand Up @@ -105,6 +110,12 @@ class matrix(N.ndarray):
"""
__array_priority__ = 10.0
def __new__(subtype, data, dtype=None, copy=True):
warnings.warn('the matrix subclass is not the recommended way to '
'represent matrices or deal with linear algebra (see '
'https://docs.scipy.org/doc/numpy/user/'
'numpy-for-matlab-users.html). '
'Please adjust your code to use regular ndarray.',
PendingDeprecationWarning, stacklevel=2)
if isinstance(data, matrix):
dtype2 = data.dtype
if (dtype is None):
Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_defmatrix.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

try:
# Accessing collections abstract classes from collections
# has been deprecated since Python 3.3
Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_interaction.py
Expand Up @@ -4,6 +4,14 @@
"""
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import textwrap
import warnings

Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_masked_matrix.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import pickle

import numpy as np
Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_matrix_linalg.py
@@ -1,6 +1,14 @@
""" Test functions for linalg module using the matrix class."""
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import numpy as np

from numpy.linalg.tests.test_linalg import (
Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_multiarray.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import numpy as np
from numpy.testing import assert_, assert_equal, assert_array_equal

Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_numeric.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import numpy as np
from numpy.testing import assert_equal

Expand Down
8 changes: 8 additions & 0 deletions numpy/matrixlib/tests/test_regression.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import numpy as np
from numpy.testing import assert_, assert_equal, assert_raises

Expand Down
8 changes: 8 additions & 0 deletions numpy/tests/test_matlib.py
@@ -1,5 +1,13 @@
from __future__ import division, absolute_import, print_function

# As we are testing matrices, we ignore its PendingDeprecationWarnings
try:
import pytest
pytestmark = pytest.mark.filterwarnings(
'ignore:the matrix subclass is not:PendingDeprecationWarning')
except ImportError:
pass

import numpy as np
import numpy.matlib
from numpy.testing import assert_array_equal, assert_
Expand Down