summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/_ufunc_config.py12
-rw-r--r--numpy/core/code_generators/generate_umath.py1
-rw-r--r--numpy/core/defchararray.py2
-rw-r--r--numpy/core/multiarray.py4
-rw-r--r--numpy/core/setup.py2
-rw-r--r--numpy/core/setup_common.py35
-rw-r--r--numpy/core/src/multiarray/scalarapi.c28
-rw-r--r--numpy/core/tests/test_mem_overlap.py17
-rw-r--r--numpy/core/tests/test_memmap.py3
-rw-r--r--numpy/core/tests/test_multiarray.py9
-rw-r--r--numpy/core/tests/test_records.py13
-rw-r--r--numpy/core/tests/test_scalarprint.py5
-rw-r--r--numpy/core/tests/test_umath_accuracy.py2
-rw-r--r--numpy/core/umath.py4
-rw-r--r--numpy/distutils/ccompiler.py11
-rw-r--r--numpy/distutils/core.py2
-rw-r--r--numpy/distutils/log.py4
-rw-r--r--numpy/distutils/misc_util.py14
-rw-r--r--numpy/distutils/unixccompiler.py4
-rw-r--r--numpy/lib/function_base.py9
-rw-r--r--numpy/lib/npyio.py2
-rw-r--r--numpy/lib/tests/test_io.py5
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/matlib.py2
-rw-r--r--numpy/matrixlib/tests/test_defmatrix.py9
-rw-r--r--numpy/matrixlib/tests/test_interaction.py27
-rw-r--r--numpy/testing/_private/decorators.py13
-rw-r--r--numpy/testing/tests/test_utils.py18
-rw-r--r--numpy/tests/test_warnings.py2
29 files changed, 83 insertions, 178 deletions
diff --git a/numpy/core/_ufunc_config.py b/numpy/core/_ufunc_config.py
index 4872a5385..454d911cf 100644
--- a/numpy/core/_ufunc_config.py
+++ b/numpy/core/_ufunc_config.py
@@ -3,12 +3,7 @@ Functions for changing global ufunc configuration
This provides helpers which wrap `umath.geterrobj` and `umath.seterrobj`
"""
-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 contextlib
from .overrides import set_module
@@ -307,8 +302,9 @@ def seterrcall(func):
OrderedDict([('divide', 'log'), ('invalid', 'log'), ('over', 'log'), ('under', 'log')])
"""
- if func is not None and not isinstance(func, collections_abc.Callable):
- if not hasattr(func, 'write') or not isinstance(func.write, collections_abc.Callable):
+ if func is not None and not isinstance(func, collections.abc.Callable):
+ if (not hasattr(func, 'write') or
+ not isinstance(func.write, collections.abc.Callable)):
raise ValueError("Only callable can be used as callback")
pyvals = umath.geterrobj()
old = geterrcall()
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 7599360f5..f9ee7d993 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -298,6 +298,7 @@ defdict = {
],
TD(O, f='PyNumber_Multiply'),
),
+#'divide' : aliased to true_divide in umathmodule.c:initumath
'floor_divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
docstrings.get('numpy.core.umath.floor_divide'),
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index 1cfdc55c0..bc101f84b 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -1908,7 +1908,7 @@ class chararray(ndarray):
unicode : bool, optional
Are the array elements of type unicode (True) or string (False).
Default is False.
- buffer : int, optional
+ buffer : object exposing the buffer interface or str, optional
Memory address of the start of the array data. Default is None,
in which case a new array is created.
offset : int, optional
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index 5749afdcc..d8adc640e 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -14,8 +14,8 @@ import sys
from . import overrides
from . import _multiarray_umath
import numpy as np
-from numpy.core._multiarray_umath import *
-from numpy.core._multiarray_umath import (
+from ._multiarray_umath import * # noqa: F403
+from ._multiarray_umath import (
_fastCopyAndTranspose, _flagdict, _insert, _reconstruct, _vec_string,
_ARRAY_API, _monotonicity, _get_ndarray_c_version
)
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index e376d5a23..66c1b782e 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -14,7 +14,7 @@ from numpy._build_utils.apple_accelerate import (
uses_accelerate_framework, get_sgemv_fix
)
from numpy.compat import npy_load_module
-from setup_common import *
+from setup_common import * # noqa: F403
# Set to True to enable relaxed strides checking. This (mostly) means
# that `strides[dim]` is ignored if `shape[dim] == 1` when setting flags.
diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py
index 6d8e603a7..08337a81e 100644
--- a/numpy/core/setup_common.py
+++ b/numpy/core/setup_common.py
@@ -311,32 +311,15 @@ def pyod(filename):
We only implement enough to get the necessary information for long double
representation, this is not intended as a compatible replacement for od.
"""
- def _pyod2():
- out = []
-
- with open(filename, 'rb') as fid:
- yo = [int(oct(int(binascii.b2a_hex(o), 16))) for o in fid.read()]
- for i in range(0, len(yo), 16):
- line = ['%07d' % int(oct(i))]
- line.extend(['%03d' % c for c in yo[i:i+16]])
- out.append(" ".join(line))
- return out
-
- def _pyod3():
- out = []
-
- with open(filename, 'rb') as fid:
- yo2 = [oct(o)[2:] for o in fid.read()]
- for i in range(0, len(yo2), 16):
- line = ['%07d' % int(oct(i)[2:])]
- line.extend(['%03d' % int(c) for c in yo2[i:i+16]])
- out.append(" ".join(line))
- return out
-
- if sys.version_info[0] < 3:
- return _pyod2()
- else:
- return _pyod3()
+ out = []
+ with open(filename, 'rb') as fid:
+ yo2 = [oct(o)[2:] for o in fid.read()]
+ for i in range(0, len(yo2), 16):
+ line = ['%07d' % int(oct(i)[2:])]
+ line.extend(['%03d' % int(c) for c in yo2[i:i+16]])
+ out.append(" ".join(line))
+ return out
+
_BEFORE_SEQ = ['000', '000', '000', '000', '000', '000', '000', '000',
'001', '043', '105', '147', '211', '253', '315', '357']
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 3a66df454..5c4332364 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -45,7 +45,7 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
type_num = descr->type_num;
}
switch (type_num) {
-#define CASE(ut,lt) case NPY_##ut: return &(((Py##lt##ScalarObject *)scalar)->obval)
+#define CASE(ut,lt) case NPY_##ut: return &PyArrayScalar_VAL(scalar, lt)
CASE(BOOL, Bool);
CASE(BYTE, Byte);
CASE(UBYTE, UByte);
@@ -73,7 +73,8 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
case NPY_UNICODE:
return (void *)PyUnicode_AS_DATA(scalar);
case NPY_VOID:
- return ((PyVoidScalarObject *)scalar)->obval;
+ /* Note: no & needed here, so can't use CASE */
+ return PyArrayScalar_VAL(scalar, Void);
}
/*
@@ -81,14 +82,13 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
* scalar it inherits from.
*/
-#define _CHK(cls) (PyObject_IsInstance(scalar, \
- (PyObject *)&Py##cls##ArrType_Type))
-#define _OBJ(lt) &(((Py##lt##ScalarObject *)scalar)->obval)
-#define _IFCASE(cls) if _CHK(cls) return _OBJ(cls)
+#define _CHK(cls) PyObject_IsInstance(scalar, \
+ (PyObject *)&Py##cls##ArrType_Type)
+#define _IFCASE(cls) if (_CHK(cls)) return &PyArrayScalar_VAL(scalar, cls)
- if _CHK(Number) {
- if _CHK(Integer) {
- if _CHK(SignedInteger) {
+ if (_CHK(Number)) {
+ if (_CHK(Integer)) {
+ if (_CHK(SignedInteger)) {
_IFCASE(Byte);
_IFCASE(Short);
_IFCASE(Int);
@@ -107,7 +107,7 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
else {
/* Inexact */
- if _CHK(Floating) {
+ if (_CHK(Floating)) {
_IFCASE(Half);
_IFCASE(Float);
_IFCASE(Double);
@@ -122,10 +122,10 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
}
else if (_CHK(Bool)) {
- return _OBJ(Bool);
+ return &PyArrayScalar_VAL(scalar, Bool);
}
else if (_CHK(Datetime)) {
- return _OBJ(Datetime);
+ return &PyArrayScalar_VAL(scalar, Datetime);
}
else if (_CHK(Flexible)) {
if (_CHK(String)) {
@@ -135,7 +135,8 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
return (void *)PyUnicode_AS_DATA(scalar);
}
if (_CHK(Void)) {
- return ((PyVoidScalarObject *)scalar)->obval;
+ /* Note: no & needed here, so can't use _IFCASE */
+ return PyArrayScalar_VAL(scalar, Void);
}
}
else {
@@ -156,7 +157,6 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
}
return (void *)memloc;
#undef _IFCASE
-#undef _OBJ
#undef _CHK
}
diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py
index 7c1cff9b7..d3b58d8e8 100644
--- a/numpy/core/tests/test_mem_overlap.py
+++ b/numpy/core/tests/test_mem_overlap.py
@@ -42,9 +42,7 @@ def _indices_for_axis():
res = []
for nelems in (0, 2, 3):
ind = _indices_for_nelems(nelems)
-
- # no itertools.product available in Py2.4
- res.extend([(a, b) for a in ind for b in ind]) # all assignments of size "nelems"
+ res.extend(itertools.product(ind, ind)) # all assignments of size "nelems"
return res
@@ -53,18 +51,7 @@ def _indices(ndims):
"""Returns ((axis0_src, axis0_dst), (axis1_src, axis1_dst), ... ) index pairs."""
ind = _indices_for_axis()
-
- # no itertools.product available in Py2.4
-
- res = [[]]
- for i in range(ndims):
- newres = []
- for elem in ind:
- for others in res:
- newres.append([elem] + others)
- res = newres
-
- return res
+ return itertools.product(ind, repeat=ndims)
def _check_assignment(srcidx, dstidx):
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index bae7a318a..feef80ce8 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -3,11 +3,11 @@ import os
import shutil
import mmap
import pytest
+from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryFile, mktemp, mkdtemp
from numpy import (
memmap, sum, average, product, ndarray, isscalar, add, subtract, multiply)
-from numpy.compat import Path
from numpy import arange, allclose, asarray
from numpy.testing import (
@@ -74,7 +74,6 @@ class TestMemmap:
del b
del fp
- @pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_path(self):
tmpname = mktemp('', 'mmap', dir=self.tempdir)
fp = memmap(Path(tmpname), dtype=self.dtype, mode='w+',
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 270daad1e..16f4f0b80 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1,9 +1,4 @@
-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 tempfile
import sys
import shutil
@@ -7756,7 +7751,7 @@ class TestHashing:
def test_collections_hashable(self):
x = np.array([])
- assert_(not isinstance(x, collections_abc.Hashable))
+ assert_(not isinstance(x, collections.abc.Hashable))
class TestArrayPriority:
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index bf43fedcc..4350a3407 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -1,16 +1,10 @@
-import sys
-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 textwrap
from os import path
+from pathlib import Path
import pytest
import numpy as np
-from numpy.compat import Path
from numpy.testing import (
assert_, assert_equal, assert_array_equal, assert_array_almost_equal,
assert_raises, temppath,
@@ -252,7 +246,7 @@ class TestFromrecords:
assert_array_equal(ra['shape'], [['A', 'B', 'C']])
ra.field = 5
assert_array_equal(ra['field'], [[5, 5, 5]])
- assert_(isinstance(ra.field, collections_abc.Callable))
+ assert_(isinstance(ra.field, collections.abc.Callable))
def test_fromrecords_with_explicit_dtype(self):
a = np.rec.fromrecords([(1, 'a'), (2, 'bbb')],
@@ -319,7 +313,6 @@ class TestFromrecords:
assert_equal(rec['f1'], [b'', b'', b''])
-@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
class TestPathUsage:
# Test that pathlib.Path can be used
def test_tofile_fromfile(self):
diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py
index 225b8295f..3293d0426 100644
--- a/numpy/core/tests/test_scalarprint.py
+++ b/numpy/core/tests/test_scalarprint.py
@@ -82,10 +82,7 @@ class TestRealScalars:
orig_stdout, orig_stderr = sys.stdout, sys.stderr
sys.stdout, sys.stderr = fo, fe
- # py2 code.interact sends irrelevant internal DeprecationWarnings
- with suppress_warnings() as sup:
- sup.filter(DeprecationWarning)
- code.interact(local={'np': np}, readfunc=input_func, banner='')
+ code.interact(local={'np': np}, readfunc=input_func, banner='')
sys.stdout, sys.stderr = orig_stdout, orig_stderr
diff --git a/numpy/core/tests/test_umath_accuracy.py b/numpy/core/tests/test_umath_accuracy.py
index 677d9af60..32211974c 100644
--- a/numpy/core/tests/test_umath_accuracy.py
+++ b/numpy/core/tests/test_umath_accuracy.py
@@ -3,7 +3,7 @@ import platform
from os import path
import sys
import pytest
-from ctypes import *
+from ctypes import c_float, c_int, cast, pointer, POINTER
from numpy.testing import assert_array_max_ulp
runtest = sys.platform.startswith('linux') and (platform.machine() == 'x86_64')
diff --git a/numpy/core/umath.py b/numpy/core/umath.py
index f3b26ab72..c3cebb03f 100644
--- a/numpy/core/umath.py
+++ b/numpy/core/umath.py
@@ -7,8 +7,8 @@ by importing from the extension module.
"""
from . import _multiarray_umath
-from numpy.core._multiarray_umath import *
-from numpy.core._multiarray_umath import (
+from ._multiarray_umath import * # noqa: F403
+from ._multiarray_umath import (
_UFUNC_API, _add_newdoc_ufunc, _ones_like
)
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py
index ea7912feb..dc7ae6d46 100644
--- a/numpy/distutils/ccompiler.py
+++ b/numpy/distutils/ccompiler.py
@@ -7,9 +7,14 @@ import time
import subprocess
from copy import copy
from distutils import ccompiler
-from distutils.ccompiler import *
-from distutils.errors import DistutilsExecError, DistutilsModuleError, \
- DistutilsPlatformError, CompileError
+from distutils.ccompiler import (
+ compiler_class, gen_lib_options, get_default_compiler, new_compiler,
+ CCompiler
+)
+from distutils.errors import (
+ DistutilsExecError, DistutilsModuleError, DistutilsPlatformError,
+ CompileError, UnknownFileError
+)
from distutils.sysconfig import customize_compiler
from distutils.version import LooseVersion
diff --git a/numpy/distutils/core.py b/numpy/distutils/core.py
index a78bbf484..d3461aa49 100644
--- a/numpy/distutils/core.py
+++ b/numpy/distutils/core.py
@@ -1,5 +1,5 @@
import sys
-from distutils.core import *
+from distutils.core import Distribution, setup
if 'setuptools' in sys.modules:
have_setuptools = True
diff --git a/numpy/distutils/log.py b/numpy/distutils/log.py
index 79eec00a6..a8113b9c6 100644
--- a/numpy/distutils/log.py
+++ b/numpy/distutils/log.py
@@ -1,6 +1,6 @@
-# Colored log, requires Python 2.3 or up.
+# Colored log
import sys
-from distutils.log import *
+from distutils.log import * # noqa: F403
from distutils.log import Log as old_Log
from distutils.log import _global_log
diff --git a/numpy/distutils/misc_util.py b/numpy/distutils/misc_util.py
index f9d2be716..68fd9ea36 100644
--- a/numpy/distutils/misc_util.py
+++ b/numpy/distutils/misc_util.py
@@ -923,18 +923,8 @@ class Configuration:
else:
pn = dot_join(*([parent_name] + subpackage_name.split('.')[:-1]))
args = (pn,)
- def fix_args_py2(args):
- if setup_module.configuration.__code__.co_argcount > 1:
- args = args + (self.top_path,)
- return args
- def fix_args_py3(args):
- if setup_module.configuration.__code__.co_argcount > 1:
- args = args + (self.top_path,)
- return args
- if sys.version_info[0] < 3:
- args = fix_args_py2(args)
- else:
- args = fix_args_py3(args)
+ if setup_module.configuration.__code__.co_argcount > 1:
+ args = args + (self.top_path,)
config = setup_module.configuration(*args)
if config.name!=dot_join(parent_name, subpackage_name):
self.warn('Subpackage %r configuration returned as %r' % \
diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py
index cf62cb019..5f36c439f 100644
--- a/numpy/distutils/unixccompiler.py
+++ b/numpy/distutils/unixccompiler.py
@@ -4,8 +4,8 @@ unixccompiler - can handle very long argument lists for ar.
"""
import os
-from distutils.errors import DistutilsExecError, CompileError
-from distutils.unixccompiler import *
+from distutils.errors import CompileError, DistutilsExecError, LibError
+from distutils.unixccompiler import UnixCCompiler
from numpy.distutils.ccompiler import replace_method
from numpy.distutils.misc_util import _commandline_dep_string
from numpy.distutils import log
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index ef8a26fe3..164213bbe 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1,9 +1,4 @@
-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 functools
import re
import sys
@@ -613,7 +608,7 @@ def piecewise(x, condlist, funclist, *args, **kw):
y = zeros(x.shape, x.dtype)
for k in range(n):
item = funclist[k]
- if not isinstance(item, collections_abc.Callable):
+ if not isinstance(item, collections.abc.Callable):
y[condlist[k]] = item
else:
vals = x[condlist[k]]
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 29af488d2..48d4f7fa2 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1319,7 +1319,7 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
delimiter = asstr(delimiter)
class WriteWrap:
- """Convert to unicode in py2 or to bytes on bytestream inputs.
+ """Convert to bytes on bytestream inputs.
"""
def __init__(self, fh, encoding):
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 2d6f39e40..436cd1d24 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -7,6 +7,7 @@ import warnings
import io
import re
import pytest
+from pathlib import Path
from tempfile import NamedTemporaryFile
from io import BytesIO, StringIO
from datetime import datetime
@@ -15,7 +16,7 @@ import locale
import numpy as np
import numpy.ma as ma
from numpy.lib._iotools import ConverterError, ConversionWarning
-from numpy.compat import asbytes, bytes, Path
+from numpy.compat import asbytes, bytes
from numpy.ma.testutils import assert_equal
from numpy.testing import (
assert_warns, assert_, assert_raises_regex, assert_raises,
@@ -362,7 +363,6 @@ class TestSaveTxt:
c.seek(0)
assert_equal(c.readlines(), [b'1 3\n', b'4 6\n'])
- @pytest.mark.skipif(Path is None, reason="No pathlib.Path")
def test_multifield_view(self):
a = np.ones(1, dtype=[('x', 'i4'), ('y', 'i4'), ('z', 'f4')])
v = a[['x', 'z']]
@@ -2339,7 +2339,6 @@ M 33 21.99
assert_equal(test['f2'], 1024)
-@pytest.mark.skipif(Path is None, reason="No pathlib.Path")
class TestPathUsage:
# Test that pathlib.Path can be used
def test_loadtxt(self):
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index fcbd1d8d0..41c35026d 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -4744,7 +4744,7 @@ class MaskedArray(ndarray):
>>> x = np.ma.array([1, 2, 3])
>>> x.ids()
- (166691080, 3083169284L) # may vary
+ (166691080, 3083169284) # may vary
"""
if self._mask is nomask:
diff --git a/numpy/matlib.py b/numpy/matlib.py
index f3eb8eb4b..1f0345be4 100644
--- a/numpy/matlib.py
+++ b/numpy/matlib.py
@@ -1,7 +1,7 @@
import numpy as np
from numpy.matrixlib.defmatrix import matrix, asmatrix
# need * as we're copying the numpy namespace (FIXME: this makes little sense)
-from numpy import *
+from numpy import * # noqa: F403
__version__ = np.__version__
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index a8070898f..4cb5f3a37 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -1,9 +1,4 @@
-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
@@ -297,7 +292,7 @@ class TestMatrixReturn:
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)
diff --git a/numpy/matrixlib/tests/test_interaction.py b/numpy/matrixlib/tests/test_interaction.py
index 608416ed7..5154bd621 100644
--- a/numpy/matrixlib/tests/test_interaction.py
+++ b/numpy/matrixlib/tests/test_interaction.py
@@ -324,24 +324,17 @@ class TestConcatenatorMatrix:
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/testing/_private/decorators.py b/numpy/testing/_private/decorators.py
index 2012b80d3..661dcd91a 100644
--- a/numpy/testing/_private/decorators.py
+++ b/numpy/testing/_private/decorators.py
@@ -13,12 +13,7 @@ function name, setup and teardown functions and so on - see
``nose.tools`` for more information.
"""
-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
from .utils import SkipTest, assert_warns, HAS_REFCOUNT
@@ -129,7 +124,7 @@ def skipif(skip_condition, msg=None):
import nose
# Allow for both boolean or callable skip conditions.
- if isinstance(skip_condition, collections_abc.Callable):
+ if isinstance(skip_condition, collections.abc.Callable):
skip_val = lambda: skip_condition()
else:
skip_val = lambda: skip_condition
@@ -205,7 +200,7 @@ def knownfailureif(fail_condition, msg=None):
msg = 'Test skipped due to known failure'
# Allow for both boolean or callable known failure conditions.
- if isinstance(fail_condition, collections_abc.Callable):
+ if isinstance(fail_condition, collections.abc.Callable):
fail_val = lambda: fail_condition()
else:
fail_val = lambda: fail_condition
@@ -260,7 +255,7 @@ def deprecated(conditional=True):
with assert_warns(DeprecationWarning):
f(*args, **kwargs)
- if isinstance(conditional, collections_abc.Callable):
+ if isinstance(conditional, collections.abc.Callable):
cond = conditional()
else:
cond = conditional
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index 232ca0e83..913c67fc6 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -341,24 +341,6 @@ class TestEqual(TestArrayEqual):
self._assert_func(x, x)
self._test_not_equal(x, y)
- def test_error_message(self):
- with pytest.raises(AssertionError) as exc_info:
- self._assert_func(np.array([1, 2]), np.array([[1, 2]]))
- msg = str(exc_info.value)
- 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: array([[1, 2]])""")
-
- try:
- assert_equal(msg, msg_reference)
- except AssertionError:
- assert_equal(msg2, msg_reference)
-
def test_object(self):
#gh-12942
import datetime
diff --git a/numpy/tests/test_warnings.py b/numpy/tests/test_warnings.py
index ff75681dc..c4c206542 100644
--- a/numpy/tests/test_warnings.py
+++ b/numpy/tests/test_warnings.py
@@ -35,7 +35,7 @@ class FindFuncs(ast.NodeVisitor):
if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings':
if node.args[0].s == "ignore":
raise AssertionError(
- "ignore filter should not be used; found in "
+ "warnings should have an appropriate stacklevel; found in "
"{} on line {}".format(self.__filename, node.lineno))
if p.ls[-1] == 'warn' and (