diff options
-rw-r--r-- | doc/neps/nep-0018-array-function-protocol.rst | 3 | ||||
-rw-r--r-- | doc/release/1.7.0-notes.rst | 6 | ||||
-rw-r--r-- | doc/source/reference/internals.code-explanations.rst | 8 | ||||
-rw-r--r-- | numpy/core/include/numpy/npy_1_7_deprecated_api.h | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_defchararray.py | 26 | ||||
-rw-r--r-- | numpy/core/tests/test_errstate.py | 14 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 9 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 21 | ||||
-rw-r--r-- | numpy/lib/tests/test_format.py | 10 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 8 | ||||
-rw-r--r-- | numpy/lib/tests/test_recfunctions.py | 8 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 8 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_defmatrix.py | 14 | ||||
-rw-r--r-- | numpy/testing/tests/test_utils.py | 6 |
14 files changed, 46 insertions, 103 deletions
diff --git a/doc/neps/nep-0018-array-function-protocol.rst b/doc/neps/nep-0018-array-function-protocol.rst index e7d433e37..d4ba7879b 100644 --- a/doc/neps/nep-0018-array-function-protocol.rst +++ b/doc/neps/nep-0018-array-function-protocol.rst @@ -7,10 +7,9 @@ NEP 18 — A dispatch mechanism for NumPy's high level array functions :Author: Marten van Kerkwijk <mhvk@astro.utoronto.ca> :Author: Hameer Abbasi <hameerabbasi@yahoo.com> :Author: Eric Wieser <wieser.eric@gmail.com> -:Status: Accepted +:Status: Draft :Type: Standards Track :Created: 2018-05-29 -:Resolution: https://mail.python.org/pipermail/numpy-discussion/2018-August/078493.html Abstact ------- diff --git a/doc/release/1.7.0-notes.rst b/doc/release/1.7.0-notes.rst index 09e6924e6..f111f80dc 100644 --- a/doc/release/1.7.0-notes.rst +++ b/doc/release/1.7.0-notes.rst @@ -280,9 +280,9 @@ The macros in old_defines.h are deprecated and will be removed in the next major release (>= 2.0). The sed script tools/replace_old_macros.sed can be used to replace these macros with the newer versions. -You can test your code against the deprecated C API by #defining -NPY_NO_DEPRECATED_API to the target version number, for example -NPY_1_7_API_VERSION, before including any NumPy headers. +You can test your code against the deprecated C API by adding a line +composed of ``#define NPY_NO_DEPRECATED_API`` and the target version number, +such as ``NPY_1_7_API_VERSION``, before including any NumPy headers. The ``NPY_CHAR`` member of the ``NPY_TYPES`` enum is deprecated and will be removed in NumPy 1.8. See the discussion at diff --git a/doc/source/reference/internals.code-explanations.rst b/doc/source/reference/internals.code-explanations.rst index ca81e1676..65553e07e 100644 --- a/doc/source/reference/internals.code-explanations.rst +++ b/doc/source/reference/internals.code-explanations.rst @@ -17,7 +17,7 @@ pieces of code. The purpose behind these explanations is to enable somebody to be able to understand the ideas behind the implementation somewhat more easily than just staring at the code. Perhaps in this way, the algorithms can be improved on, borrowed from, and/or -optimized. +optimized by more people. Memory model @@ -133,9 +133,9 @@ Broadcasting .. index:: single: broadcasting -In Numeric, broadcasting was implemented in several lines of code -buried deep in ufuncobject.c. In NumPy, the notion of broadcasting has -been abstracted so that it can be performed in multiple places. +In Numeric, the ancestor of Numpy, broadcasting was implemented in several +lines of code buried deep in ufuncobject.c. In NumPy, the notion of broadcasting +has been abstracted so that it can be performed in multiple places. Broadcasting is handled by the function :c:func:`PyArray_Broadcast`. This function requires a :c:type:`PyArrayMultiIterObject` (or something that is a binary equivalent) to be passed in. The :c:type:`PyArrayMultiIterObject` keeps diff --git a/numpy/core/include/numpy/npy_1_7_deprecated_api.h b/numpy/core/include/numpy/npy_1_7_deprecated_api.h index 4c318bc47..76b57b748 100644 --- a/numpy/core/include/numpy/npy_1_7_deprecated_api.h +++ b/numpy/core/include/numpy/npy_1_7_deprecated_api.h @@ -9,11 +9,11 @@ #define _WARN___STR2__(x) #x #define _WARN___STR1__(x) _WARN___STR2__(x) #define _WARN___LOC__ __FILE__ "(" _WARN___STR1__(__LINE__) ") : Warning Msg: " -#pragma message(_WARN___LOC__"Using deprecated NumPy API, disable it by " \ - "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION") +#pragma message(_WARN___LOC__"Using deprecated NumPy API, disable it with " \ + "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION") #elif defined(__GNUC__) -#warning "Using deprecated NumPy API, disable it by " \ - "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" +#warning "Using deprecated NumPy API, disable it with " \ + "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" #endif /* TODO: How to do this warning message for other compilers? */ diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py index 43f1b71c7..7b0e6f8a4 100644 --- a/numpy/core/tests/test_defchararray.py +++ b/numpy/core/tests/test_defchararray.py @@ -6,7 +6,7 @@ import numpy as np from numpy.core.multiarray import _vec_string from numpy.testing import ( assert_, assert_equal, assert_array_equal, assert_raises, - suppress_warnings, + assert_raises_regex, suppress_warnings, ) kw_unicode_true = {'unicode': True} # make 2to3 work properly @@ -626,12 +626,9 @@ class TestOperations(object): assert_array_equal(Ar, (self.A * r)) for ob in [object(), 'qrs']: - try: - A * ob - except ValueError: - pass - else: - self.fail("chararray can only be multiplied by integers") + with assert_raises_regex(ValueError, + 'Can only multiply by integers'): + A*ob def test_rmul(self): A = self.A @@ -641,12 +638,9 @@ class TestOperations(object): assert_array_equal(Ar, (r * self.A)) for ob in [object(), 'qrs']: - try: + with assert_raises_regex(ValueError, + 'Can only multiply by integers'): ob * A - except ValueError: - pass - else: - self.fail("chararray can only be multiplied by integers") def test_mod(self): """Ticket #856""" @@ -668,13 +662,9 @@ class TestOperations(object): assert_(("%r" % self.A) == repr(self.A)) for ob in [42, object()]: - try: + with assert_raises_regex( + TypeError, "unsupported operand type.* and 'chararray'"): ob % self.A - except TypeError: - pass - else: - self.fail("chararray __rmod__ should fail with " - "non-string objects") def test_slice(self): """Regression test for https://github.com/numpy/numpy/issues/5982""" diff --git a/numpy/core/tests/test_errstate.py b/numpy/core/tests/test_errstate.py index 4f6111921..670d485c1 100644 --- a/numpy/core/tests/test_errstate.py +++ b/numpy/core/tests/test_errstate.py @@ -4,7 +4,7 @@ import platform import pytest import numpy as np -from numpy.testing import assert_ +from numpy.testing import assert_, assert_raises class TestErrstate(object): @@ -16,12 +16,8 @@ class TestErrstate(object): with np.errstate(invalid='ignore'): np.sqrt(a) # While this should fail! - try: + with assert_raises(FloatingPointError): np.sqrt(a) - except FloatingPointError: - pass - else: - self.fail("Did not raise an invalid error") def test_divide(self): with np.errstate(all='raise', under='ignore'): @@ -30,12 +26,8 @@ class TestErrstate(object): with np.errstate(divide='ignore'): a // 0 # While this should fail! - try: + with assert_raises(FloatingPointError): a // 0 - except FloatingPointError: - pass - else: - self.fail("Did not raise divide by zero error") def test_errcall(self): def foo(*args): diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index e7181736f..7e2d6d1d1 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -13,7 +13,7 @@ from numpy.random import rand, randint, randn from numpy.testing import ( assert_, assert_equal, assert_raises, assert_raises_regex, assert_array_equal, assert_almost_equal, assert_array_almost_equal, - suppress_warnings, HAS_REFCOUNT + assert_raises, suppress_warnings, HAS_REFCOUNT ) @@ -471,12 +471,9 @@ class TestSeterr(object): @pytest.mark.skipif(platform.machine() == "armv5tel", reason="See gh-413.") def test_divide_err(self): with np.errstate(divide='raise'): - try: + with assert_raises(FloatingPointError): np.array([1.]) / np.array([0.]) - except FloatingPointError: - pass - else: - self.fail() + np.seterr(divide='ignore') np.array([1.]) / np.array([0.]) diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index c38625dac..8be00dad6 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -16,7 +16,8 @@ import numpy as np from numpy.testing import ( assert_, assert_equal, IS_PYPY, assert_almost_equal, assert_array_equal, assert_array_almost_equal, assert_raises, - assert_warns, suppress_warnings, _assert_valid_refcount, HAS_REFCOUNT, + assert_raises_regex, assert_warns, suppress_warnings, + _assert_valid_refcount, HAS_REFCOUNT, ) from numpy.compat import asbytes, asunicode, long @@ -1309,28 +1310,18 @@ class TestRegression(object): # Regression test for #1061. # Set a size which cannot fit into a 64 bits signed integer sz = 2 ** 64 - good = 'Maximum allowed dimension exceeded' - try: + with assert_raises_regex(ValueError, + 'Maximum allowed dimension exceeded'): np.empty(sz) - except ValueError as e: - if not str(e) == good: - self.fail("Got msg '%s', expected '%s'" % (e, good)) - except Exception as e: - self.fail("Got exception of type %s instead of ValueError" % type(e)) def test_huge_arange(self): # Regression test for #1062. # Set a size which cannot fit into a 64 bits signed integer sz = 2 ** 64 - good = 'Maximum allowed size exceeded' - try: + with assert_raises_regex(ValueError, + 'Maximum allowed size exceeded'): np.arange(sz) assert_(np.size == sz) - except ValueError as e: - if not str(e) == good: - self.fail("Got msg '%s', expected '%s'" % (e, good)) - except Exception as e: - self.fail("Got exception of type %s instead of ValueError" % type(e)) def test_fromiter_bytes(self): # Ticket #1058 diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index c7869c582..af64dd043 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -286,7 +286,8 @@ from io import BytesIO import numpy as np from numpy.testing import ( - assert_, assert_array_equal, assert_raises, raises, SkipTest + assert_, assert_array_equal, assert_raises, assert_raises_regex, + raises, SkipTest ) from numpy.lib import format @@ -678,12 +679,9 @@ def test_write_version(): (255, 255), ] for version in bad_versions: - try: + with assert_raises_regex(ValueError, + 'we only support format version.*'): format.write_array(f, arr, version=version) - except ValueError: - pass - else: - raise AssertionError("we should have raised a ValueError for the bad version %r" % (version,)) bad_version_magic = [ diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 24b2ec15a..711415c6a 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1454,14 +1454,10 @@ M 33 21.99 assert_equal(test, control) ndtype = [('nest', [('idx', int), ('code', object)])] - try: + with assert_raises_regex(NotImplementedError, + 'Nested fields.* not supported.*'): test = np.genfromtxt(TextIO(data), delimiter=";", dtype=ndtype, converters=converters) - except NotImplementedError: - pass - else: - errmsg = "Nested dtype involving objects should be supported." - raise AssertionError(errmsg) def test_userconverters_with_explicit_dtype(self): # Test user_converters w/ explicit (standard) dtype diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py index d4828bc1f..5585a95f9 100644 --- a/numpy/lib/tests/test_recfunctions.py +++ b/numpy/lib/tests/test_recfunctions.py @@ -541,12 +541,8 @@ class TestStackArrays(object): test = stack_arrays((a, b), autoconvert=True) assert_equal(test, control) assert_equal(test.mask, control.mask) - try: - test = stack_arrays((a, b), autoconvert=False) - except TypeError: - pass - else: - raise AssertionError + with assert_raises(TypeError): + stack_arrays((a, b), autoconvert=False) def test_checktitles(self): # Test using titles in the field names diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index a08a0d956..21e0fc41a 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -3806,12 +3806,8 @@ class TestMaskedArrayFunctions(object): def test_masked_where_shape_constraint(self): a = arange(10) - try: - test = masked_equal(1, a) - except IndexError: - pass - else: - raise AssertionError("Should have failed...") + with assert_raises(IndexError): + masked_equal(1, a) test = masked_equal(a, 1) assert_equal(test.mask, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]) diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py index 4cff5ee9b..f8a8ad511 100644 --- a/numpy/matrixlib/tests/test_defmatrix.py +++ b/numpy/matrixlib/tests/test_defmatrix.py @@ -268,21 +268,13 @@ class TestAlgebra(object): [3., 4.]]) # __rpow__ - try: + with assert_raises(TypeError): 1.0**A - except TypeError: - pass - else: - self.fail("matrix.__rpow__ doesn't raise a TypeError") # __mul__ with something not a list, ndarray, tuple, or scalar - try: + with assert_raises(TypeError): A*object() - except TypeError: - pass - else: - self.fail("matrix.__mul__ with non-numeric object doesn't raise" - "a TypeError") + class TestMatrixReturn(object): def test_instance_methods(self): diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 2c60e2867..54f8a281a 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -25,12 +25,8 @@ class _GenericTest(object): self._assert_func(a, b) def _test_not_equal(self, a, b): - try: + with assert_raises(AssertionError): self._assert_func(a, b) - except AssertionError: - pass - else: - raise AssertionError("a and b are found equal but are not") def test_array_rank1_eq(self): """Test two equal array of rank 1 are found equal.""" |