From 2dadfe8c6158b3f4ccdac3d044a2b6b8b91397eb Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Tue, 21 Jan 2020 16:11:33 -0800 Subject: [PATCH 1/2] DOC: Describe matlib.py funky namespace --- numpy/matlib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numpy/matlib.py b/numpy/matlib.py index 1f0345be458e..5e53f74d99b8 100644 --- a/numpy/matlib.py +++ b/numpy/matlib.py @@ -1,6 +1,8 @@ import numpy as np from numpy.matrixlib.defmatrix import matrix, asmatrix -# need * as we're copying the numpy namespace (FIXME: this makes little sense) +# Matlib.py contains all functions in the numpy namespace with a few +# replacements. See doc/source/reference/routines.matlib.rst for details. +# Need * as we're copying the numpy namespace. from numpy import * # noqa: F403 __version__ = np.__version__ From 581f1664cc24290f1257484cf2ce4df296adfb20 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Wed, 22 Jan 2020 21:54:01 -0800 Subject: [PATCH 2/2] DEP: deprecate importing numpy/matrixlib.py --- numpy/_pytesttester.py | 1 + numpy/matlib.py | 11 +++++++++++ numpy/tests/test_matlib.py | 8 -------- pytest.ini | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py index e573d53ab30e..0dc38fa59b31 100644 --- a/numpy/_pytesttester.py +++ b/numpy/_pytesttester.py @@ -153,6 +153,7 @@ def __call__(self, label='fast', verbose=1, extra_argv=None, # When testing matrices, ignore their PendingDeprecationWarnings pytest_args += [ "-W ignore:the matrix subclass is not", + "-W ignore:Importing from numpy.matlib is", ] if doctests: diff --git a/numpy/matlib.py b/numpy/matlib.py index 5e53f74d99b8..bd6b632891fc 100644 --- a/numpy/matlib.py +++ b/numpy/matlib.py @@ -1,3 +1,14 @@ +import warnings + +# 2018-05-29, PendingDeprecationWarning added to matrix.__new__ +# 2020-01-23, numpy 1.19.0 PendingDeprecatonWarning +warnings.warn("Importing from numpy.matlib is deprecated since 1.19.0. " + "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) + import numpy as np from numpy.matrixlib.defmatrix import matrix, asmatrix # Matlib.py contains all functions in the numpy namespace with a few diff --git a/numpy/tests/test_matlib.py b/numpy/tests/test_matlib.py index e04947a2e80f..0e93c4848d75 100644 --- a/numpy/tests/test_matlib.py +++ b/numpy/tests/test_matlib.py @@ -1,11 +1,3 @@ -# 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_ diff --git a/pytest.ini b/pytest.ini index 480130337f65..0db7f80ddec6 100644 --- a/pytest.ini +++ b/pytest.ini @@ -13,6 +13,7 @@ filterwarnings = ignore::UserWarning:cpuinfo, # Matrix PendingDeprecationWarning. ignore:the matrix subclass is not + ignore:Importing from numpy.matlib is env = PYTHONHASHSEED=0