From 1308c9df4c571aaf09346dae73f99fde94b10ad6 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Fri, 15 Jul 2022 11:14:49 +0900 Subject: [PATCH] Imported Upstream version 1.21.2 --- .coveragerc | 4 ++ MANIFEST.in | 3 + PKG-INFO | 5 +- _configtest.o | Bin 4888 -> 4888 bytes doc/changelog/1.21.2-changelog.rst | 41 ++++++++++++ doc/source/release.rst | 1 + doc/source/release/1.21.2-notes.rst | 59 ++++++++++++++++++ numpy/__init__.pyi | 16 +++++ numpy/_version.py | 6 +- numpy/core/code_generators/generate_umath.py | 4 +- numpy/core/include/numpy/npy_cpu.h | 7 ++- .../multiarray/lowlevel_strided_loops.c.src | 2 +- numpy/core/src/umath/ufunc_object.c | 11 ++-- numpy/core/tests/test_deprecations.py | 33 ++++++++++ numpy/core/tests/test_nditer.py | 7 ++- numpy/core/tests/test_scalarprint.py | 3 +- numpy/core/tests/test_ufunc.py | 42 ++++++------- numpy/core/tests/test_umath_complex.py | 40 ++++++++---- numpy/distutils/ccompiler_opt.py | 7 ++- numpy/distutils/system_info.py | 4 ++ numpy/lib/tests/test_utils.py | 6 +- numpy/random/src/philox/philox.h | 8 ++- numpy/typing/_array_like.py | 13 +++- numpy/typing/_dtype_like.py | 3 +- numpy/typing/tests/data/reveal/nditer.py | 19 ++++++ numpy/typing/tests/test_typing_extensions.py | 35 +++++++++++ pavement.py | 2 +- pyproject.toml | 2 +- runtests.py | 21 ++++++- setup.py | 3 +- test_requirements.txt | 2 +- tools/cythonize.py | 3 +- 32 files changed, 346 insertions(+), 66 deletions(-) create mode 100644 .coveragerc create mode 100644 doc/changelog/1.21.2-changelog.rst create mode 100644 doc/source/release/1.21.2-notes.rst create mode 100644 numpy/typing/tests/data/reveal/nditer.py create mode 100644 numpy/typing/tests/test_typing_extensions.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..9048b9cc --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[run] +branch = True +include = */numpy/* +disable_warnings = include-ignored diff --git a/MANIFEST.in b/MANIFEST.in index 8ec62123..ab6ecd51 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -12,6 +12,9 @@ exclude LICENSES_bundled.txt exclude .* exclude azure-*.yml +# Include coveragerc for runtests.py +include .coveragerc + # Sub-directories. Included are: numpy/, doc/, benchmarks/, tools/ include numpy/_version.py recursive-include numpy/random *.pyx *.pxd *.pyx.in *.pxd.in diff --git a/PKG-INFO b/PKG-INFO index 8977ea80..26d4e367 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.2 Name: numpy -Version: 1.21.1 +Version: 1.21.2 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. @@ -42,6 +42,7 @@ Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development @@ -51,4 +52,4 @@ Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: POSIX Classifier: Operating System :: Unix Classifier: Operating System :: MacOS -Requires-Python: >=3.7 +Requires-Python: >=3.7,<3.11 diff --git a/_configtest.o b/_configtest.o index 8fdec4ddf62d02a266a062df9a48559e4ae330ee..4d632006d5e4754b83b4d9e4e54f312b60d829a5 100644 GIT binary patch delta 129 zcmbQCHbZU0HbzZ%zfc8dLvsZ~Lp>usLj@xPBSQmoBMSwMpwtuvkHiwFgs$P{w~VqZ zjK-U}+1MC)9YcKLlS(slQZn<>@+S+hH_H*wyper96C=aqM6PlsU)IgHxa>FpYH}e~ delta 130 zcmbQCHbZU0Hb!&D5TE#@(#)Kc%)GRG26w+u1!qHZ1w%tUAXG3iFfueSH8xbx2ue*+ z@JK9yO6VGIzRxJj!f3SlFDo14WI^^OIReTzvae@i`__: MAINT: set Python version for 1.21.x to ``<3.11`` +* `#19533 `__: BUG: Fix an issue wherein importing ``numpy.typing`` could raise +* `#19646 `__: MAINT: Update Cython version for Python 3.10. +* `#19648 `__: TST: Bump the python 3.10 test version from beta4 to rc1 +* `#19651 `__: TST: avoid distutils.sysconfig in runtests.py +* `#19652 `__: MAINT: add missing dunder method to nditer type hints +* `#19656 `__: BLD, SIMD: Fix testing extra checks when ``-Werror`` isn't applicable... +* `#19657 `__: BUG: Remove logical object ufuncs with bool output +* `#19658 `__: MAINT: Include .coveragerc in source distributions to support... +* `#19659 `__: BUG: Fix bad write in masked iterator output copy paths +* `#19660 `__: ENH: Add support for windows on arm targets +* `#19661 `__: BUG: add base to templated arguments for platlib +* `#19662 `__: BUG,DEP: Non-default UFunc signature/dtype usage should be deprecated +* `#19666 `__: MAINT: Add Python 3.10 to supported versions. +* `#19668 `__: TST,BUG: Sanitize path-separators when running ``runtest.py`` +* `#19671 `__: BLD: load extra flags when checking for libflame +* `#19676 `__: BLD: update circleCI docker image +* `#19677 `__: REL: Prepare for 1.21.2 release. diff --git a/doc/source/release.rst b/doc/source/release.rst index 4a9d2b19..99856e99 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -5,6 +5,7 @@ Release Notes .. toctree:: :maxdepth: 3 + 1.21.2 1.21.1 1.21.0 1.20.3 diff --git a/doc/source/release/1.21.2-notes.rst b/doc/source/release/1.21.2-notes.rst new file mode 100644 index 00000000..ee2c525c --- /dev/null +++ b/doc/source/release/1.21.2-notes.rst @@ -0,0 +1,59 @@ +.. currentmodule:: numpy + +========================== +NumPy 1.21.2 Release Notes +========================== + +The NumPy 1.21.2 is maintenance release that fixes bugs discovered after +1.21.1. It also provides 64 bit manylinux Python 3.10.0rc1 wheels for +downstream testing. Note that Python 3.10 is not yet final. There is also +preliminary support for Windows on ARM64 builds, but there is no OpenBLAS for +that platform and no wheels are available. + +The Python versions supported for this release are 3.7-3.9. The 1.21.x series +is compatible with Python 3.10.0rc1 and Python 3.10 will be officially +supported after it is released. The previous problems with gcc-11.1 have been +fixed by gcc-11.2, check your version if you are using gcc-11. + + +Contributors +============ + +A total of 10 people contributed to this release. People with a "+" by their +names contributed a patch for the first time. + +* Bas van Beek +* Carl Johnsen + +* Charles Harris +* Gwyn Ciesla + +* Matthieu Dartiailh +* Matti Picus +* Niyas Sait + +* Ralf Gommers +* Sayed Adel +* Sebastian Berg + + +Pull requests merged +==================== + +A total of 18 pull requests were merged for this release. + +* `#19497 `__: MAINT: set Python version for 1.21.x to ``<3.11`` +* `#19533 `__: BUG: Fix an issue wherein importing ``numpy.typing`` could raise +* `#19646 `__: MAINT: Update Cython version for Python 3.10. +* `#19648 `__: TST: Bump the python 3.10 test version from beta4 to rc1 +* `#19651 `__: TST: avoid distutils.sysconfig in runtests.py +* `#19652 `__: MAINT: add missing dunder method to nditer type hints +* `#19656 `__: BLD, SIMD: Fix testing extra checks when ``-Werror`` isn't applicable... +* `#19657 `__: BUG: Remove logical object ufuncs with bool output +* `#19658 `__: MAINT: Include .coveragerc in source distributions to support... +* `#19659 `__: BUG: Fix bad write in masked iterator output copy paths +* `#19660 `__: ENH: Add support for windows on arm targets +* `#19661 `__: BUG: add base to templated arguments for platlib +* `#19662 `__: BUG,DEP: Non-default UFunc signature/dtype usage should be deprecated +* `#19666 `__: MAINT: Add Python 3.10 to supported versions. +* `#19668 `__: TST,BUG: Sanitize path-separators when running ``runtest.py`` +* `#19671 `__: BLD: load extra flags when checking for libflame +* `#19676 `__: BLD: update circleCI docker image +* `#19677 `__: REL: Prepare for 1.21.2 release. diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 74c33b16..d07e32f1 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -169,6 +169,7 @@ from typing import ( Generic, IO, Iterable, + Iterator, List, Mapping, NoReturn, @@ -729,6 +730,21 @@ class nditer: buffersize: Any = ..., ) -> Any: ... def __getattr__(self, key: str) -> Any: ... + def __enter__(self) -> nditer: ... + def __exit__( + self, + exc_type: None | Type[BaseException], + exc_value: None | BaseException, + traceback: None | TracebackType, + ) -> None: ... + def __iter__(self) -> Iterator[Any]: ... + def __next__(self) -> Any: ... + def __len__(self) -> int: ... + def __copy__(self) -> nditer: ... + def __getitem__(self, index: SupportsIndex | slice) -> Any: ... + def __setitem__(self, index: SupportsIndex | slice, value: Any) -> None: ... + def __delitem__(self, key: SupportsIndex | slice) -> None: ... + class poly1d: def __init__( diff --git a/numpy/_version.py b/numpy/_version.py index 0a5a25f2..582f1962 100644 --- a/numpy/_version.py +++ b/numpy/_version.py @@ -8,11 +8,11 @@ import json version_json = ''' { - "date": "2021-07-18T11:34:41-0600", + "date": "2021-08-15T12:15:47-0600", "dirty": false, "error": null, - "full-revisionid": "df6d2600c51502e1877aac563658d0616a75c5e5", - "version": "1.21.1" + "full-revisionid": "2fe48d2d98a85c8ea3f3d5caffd952ea69e99335", + "version": "1.21.2" } ''' # END VERSION_JSON diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index 9e94f9cc..d567b2eb 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -489,7 +489,6 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalAnd'), - TD(O, f='npy_ObjectLogicalAnd', out='?'), ), 'logical_not': Ufunc(1, 1, None, @@ -497,7 +496,6 @@ defdict = { None, TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalNot'), - TD(O, f='npy_ObjectLogicalNot', out='?'), ), 'logical_or': Ufunc(2, 1, False_, @@ -505,13 +503,13 @@ defdict = { 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]), TD(O, f='npy_ObjectLogicalOr'), - TD(O, f='npy_ObjectLogicalOr', out='?'), ), 'logical_xor': Ufunc(2, 1, False_, docstrings.get('numpy.core.umath.logical_xor'), 'PyUFunc_SimpleBinaryComparisonTypeResolver', TD(nodatetime_or_obj, out='?'), + # TODO: using obj.logical_xor() seems pretty much useless: TD(P, f='logical_xor'), ), 'maximum': diff --git a/numpy/core/include/numpy/npy_cpu.h b/numpy/core/include/numpy/npy_cpu.h index 065176ac..bc1fad72 100644 --- a/numpy/core/include/numpy/npy_cpu.h +++ b/numpy/core/include/numpy/npy_cpu.h @@ -63,7 +63,8 @@ #define NPY_CPU_HPPA #elif defined(__alpha__) #define NPY_CPU_ALPHA -#elif defined(__arm__) || defined(__aarch64__) +#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64) + /* _M_ARM64 is defined in MSVC for ARM64 compilation on Windows */ #if defined(__ARMEB__) || defined(__AARCH64EB__) #if defined(__ARM_32BIT_STATE) #define NPY_CPU_ARMEB_AARCH32 @@ -72,10 +73,10 @@ #else #define NPY_CPU_ARMEB #endif - #elif defined(__ARMEL__) || defined(__AARCH64EL__) + #elif defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64) #if defined(__ARM_32BIT_STATE) #define NPY_CPU_ARMEL_AARCH32 - #elif defined(__ARM_64BIT_STATE) + #elif defined(__ARM_64BIT_STATE) || defined(_M_ARM64) #define NPY_CPU_ARMEL_AARCH64 #else #define NPY_CPU_ARMEL diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src index 631042da..e533e493 100644 --- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src +++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src @@ -1316,7 +1316,7 @@ PyArray_TransferMaskedStridedToNDim(npy_intp ndim, args, &count, strides, mask, mask_stride, cast_info->auxdata); } int res = stransfer(&cast_info->context, - args, &count, strides, mask, mask_stride, cast_info->auxdata); + args, &N, strides, mask, mask_stride, cast_info->auxdata); if (res < 0) { return -1; } diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 9e73dfd9..068ff2d7 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -4436,7 +4436,8 @@ _get_dtype(PyObject *dtype_obj) { else if (NPY_UNLIKELY(out->singleton != descr)) { /* This does not warn about `metadata`, but units is important. */ if (!PyArray_EquivTypes(out->singleton, descr)) { - PyErr_Format(PyExc_TypeError, + /* Deprecated NumPy 1.21.2 (was an accidental error in 1.21) */ + if (DEPRECATE( "The `dtype` and `signature` arguments to " "ufuncs only select the general DType and not details " "such as the byte order or time unit (with rare " @@ -4446,9 +4447,11 @@ _get_dtype(PyObject *dtype_obj) { "In rare cases where the time unit was preserved, " "either cast the inputs or provide an output array. " "In the future NumPy may transition to allow providing " - "`dtype=` to denote the outputs `dtype` as well"); - Py_DECREF(descr); - return NULL; + "`dtype=` to denote the outputs `dtype` as well. " + "(Deprecated NumPy 1.21)") < 0) { + Py_DECREF(descr); + return NULL; + } } } Py_INCREF(out); diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 42e632e4..29603e3c 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -1174,3 +1174,36 @@ class TestCtypesGetter(_DeprecationTestCase): ) def test_not_deprecated(self, name: str) -> None: self.assert_not_deprecated(lambda: getattr(self.ctypes, name)) + + +class TestUFuncForcedDTypeWarning(_DeprecationTestCase): + message = "The `dtype` and `signature` arguments to ufuncs only select the" + + def test_not_deprecated(self): + import pickle + # does not warn (test relies on bad pickling behaviour, simply remove + # it if the `assert int64 is not int64_2` should start failing. + int64 = np.dtype("int64") + int64_2 = pickle.loads(pickle.dumps(int64)) + assert int64 is not int64_2 + self.assert_not_deprecated(lambda: np.add(3, 4, dtype=int64_2)) + + def test_deprecation(self): + int64 = np.dtype("int64") + self.assert_deprecated(lambda: np.add(3, 5, dtype=int64.newbyteorder())) + self.assert_deprecated(lambda: np.add(3, 5, dtype="m8[ns]")) + + def test_behaviour(self): + int64 = np.dtype("int64") + arr = np.arange(10, dtype="m8[s]") + + with pytest.warns(DeprecationWarning, match=self.message): + np.add(3, 5, dtype=int64.newbyteorder()) + with pytest.warns(DeprecationWarning, match=self.message): + np.add(3, 5, dtype="m8[ns]") # previously used the "ns" + with pytest.warns(DeprecationWarning, match=self.message): + np.add(arr, arr, dtype="m8[ns]") # never preserved the "ns" + with pytest.warns(DeprecationWarning, match=self.message): + np.maximum(arr, arr, dtype="m8[ns]") # previously used the "ns" + with pytest.warns(DeprecationWarning, match=self.message): + np.maximum.reduce(arr, dtype="m8[ns]") # never preserved the "ns" diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index adcf921f..6b743ab2 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -2738,7 +2738,12 @@ def _is_buffered(iterator): @pytest.mark.parametrize("a", [np.zeros((3,), dtype='f8'), np.zeros((9876, 3*5), dtype='f8')[::2, :], - np.zeros((4, 312, 124, 3), dtype='f8')[::2, :, ::2, :]]) + np.zeros((4, 312, 124, 3), dtype='f8')[::2, :, ::2, :], + # Also test with the last dimension strided (so it does not fit if + # there is repeated access) + np.zeros((9,), dtype='f8')[::3], + np.zeros((9876, 3*10), dtype='f8')[::2, ::5], + np.zeros((4, 312, 124, 3), dtype='f8')[::2, :, ::2, ::-1]]) def test_iter_writemasked(a): # Note, the slicing above is to ensure that nditer cannot combine multiple # axes into one. The repetition is just to make things a bit more diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py index 62047268..2f1c3bc5 100644 --- a/numpy/core/tests/test_scalarprint.py +++ b/numpy/core/tests/test_scalarprint.py @@ -154,7 +154,8 @@ class TestRealScalars: "0.00000000000000000000000000000000000000000000140129846432" "4817070923729583289916131280261941876515771757068283889791" "08268586060148663818836212158203125") - assert_equal(fpos64(0.5**(1022 + 52), unique=False, precision=1074), + + assert_equal(fpos64(5e-324, unique=False, precision=1074), "0.00000000000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000" diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index a47f1df4..091b4761 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -517,27 +517,6 @@ class TestUfunc: np.add(arr, arr, dtype="m") np.maximum(arr, arr, dtype="m") - def test_forced_dtype_warning(self): - # does not warn (test relies on bad pickling behaviour, simply remove - # it if the `assert int64 is not int64_2` should start failing. - int64 = np.dtype("int64") - int64_2 = pickle.loads(pickle.dumps(int64)) - assert int64 is not int64_2 - np.add(3, 4, dtype=int64_2) - - arr = np.arange(10, dtype="m8[s]") - msg = "The `dtype` and `signature` arguments to ufuncs only select the" - with pytest.raises(TypeError, match=msg): - np.add(3, 5, dtype=int64.newbyteorder()) - with pytest.raises(TypeError, match=msg): - np.add(3, 5, dtype="m8[ns]") # previously used the "ns" - with pytest.raises(TypeError, match=msg): - np.add(arr, arr, dtype="m8[ns]") # never preserved the "ns" - with pytest.raises(TypeError, match=msg): - np.maximum(arr, arr, dtype="m8[ns]") # previously used the "ns" - with pytest.raises(TypeError, match=msg): - np.maximum.reduce(arr, dtype="m8[ns]") # never preserved the "ns" - def test_true_divide(self): a = np.array(10) b = np.array(20) @@ -2029,6 +2008,27 @@ class TestUfunc: assert_raises(TypeError, f, a, b) assert_raises(TypeError, f, c, a) + @pytest.mark.parametrize("ufunc", + [np.logical_and, np.logical_or]) # logical_xor object loop is bad + @pytest.mark.parametrize("signature", + [(None, None, object), (object, None, None), + (None, object, None)]) + def test_logical_ufuncs_object_signatures(self, ufunc, signature): + a = np.array([True, None, False], dtype=object) + res = ufunc(a, a, signature=signature) + assert res.dtype == object + + @pytest.mark.parametrize("ufunc", + [np.logical_and, np.logical_or, np.logical_xor]) + @pytest.mark.parametrize("signature", + [(bool, None, object), (object, None, bool), + (None, object, bool)]) + def test_logical_ufuncs_mixed_object_signatures(self, ufunc, signature): + # Most mixed signatures fail (except those with bool out, e.g. `OO->?`) + a = np.array([True, None, False]) + with pytest.raises(TypeError): + ufunc(a, a, signature=signature) + def test_reduce_noncontig_output(self): # Check that reduction deals with non-contiguous output arrays # appropriately. diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py index c051cd61..ad09830d 100644 --- a/numpy/core/tests/test_umath_complex.py +++ b/numpy/core/tests/test_umath_complex.py @@ -372,11 +372,18 @@ class TestCpow: x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan]) y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3]) lx = list(range(len(x))) - # Compute the values for complex type in python - p_r = [complex(x[i]) ** complex(y[i]) for i in lx] - # Substitute a result allowed by C99 standard - p_r[4] = complex(np.inf, np.nan) - # Do the same with numpy complex scalars + + # Hardcode the expected `builtins.complex` values, + # as complex exponentiation is broken as of bpo-44698 + p_r = [ + 1+0j, + 0.20787957635076193+0j, + 0.35812203996480685+0.6097119028618724j, + 0.12659112128185032+0.48847676699581527j, + complex(np.inf, np.nan), + complex(np.nan, np.nan), + ] + n_r = [x[i] ** y[i] for i in lx] for i in lx: assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i) @@ -385,11 +392,18 @@ class TestCpow: x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan]) y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3]) lx = list(range(len(x))) - # Compute the values for complex type in python - p_r = [complex(x[i]) ** complex(y[i]) for i in lx] - # Substitute a result allowed by C99 standard - p_r[4] = complex(np.inf, np.nan) - # Do the same with numpy arrays + + # Hardcode the expected `builtins.complex` values, + # as complex exponentiation is broken as of bpo-44698 + p_r = [ + 1+0j, + 0.20787957635076193+0j, + 0.35812203996480685+0.6097119028618724j, + 0.12659112128185032+0.48847676699581527j, + complex(np.inf, np.nan), + complex(np.nan, np.nan), + ] + n_r = x ** y for i in lx: assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i) @@ -583,7 +597,7 @@ class TestComplexAbsoluteMixedDTypes: @pytest.mark.parametrize("stride", [-4,-3,-2,-1,1,2,3,4]) @pytest.mark.parametrize("astype", [np.complex64, np.complex128]) @pytest.mark.parametrize("func", ['abs', 'square', 'conjugate']) - + def test_array(self, stride, astype, func): dtype = [('template_id', ' #if defined(_WIN64) && defined(_M_AMD64) #pragma intrinsic(_umul128) +#elif defined(_WIN64) && defined(_M_ARM64) +#pragma intrinsic(__umulh) +static NPY_INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) { + *high = __umulh(a, b); + return a * b; +} #else #pragma intrinsic(__emulu) static NPY_INLINE uint64_t _umul128(uint64_t a, uint64_t b, uint64_t *high) { diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py index cfd9aacb..a1642f9d 100644 --- a/numpy/typing/_array_like.py +++ b/numpy/typing/_array_like.py @@ -1,7 +1,15 @@ from __future__ import annotations import sys -from typing import Any, overload, Sequence, TYPE_CHECKING, Union, TypeVar +from typing import ( + Any, + overload, + Sequence, + TYPE_CHECKING, + Union, + TypeVar, + Generic, +) from numpy import ( ndarray, @@ -47,7 +55,8 @@ if TYPE_CHECKING or HAVE_PROTOCOL: class _SupportsArray(Protocol[_DType_co]): def __array__(self) -> ndarray[Any, _DType_co]: ... else: - _SupportsArray = Any + class _SupportsArray(Generic[_DType_co]): + pass # TODO: Wait for support for recursive types _NestedSequence = Union[ diff --git a/numpy/typing/_dtype_like.py b/numpy/typing/_dtype_like.py index 636e2209..9864f46d 100644 --- a/numpy/typing/_dtype_like.py +++ b/numpy/typing/_dtype_like.py @@ -67,6 +67,8 @@ from ._char_codes import ( _ObjectCodes, ) +_DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype) + _DTypeLikeNested = Any # TODO: wait for support for recursive types if TYPE_CHECKING or HAVE_PROTOCOL: @@ -82,7 +84,6 @@ if TYPE_CHECKING or HAVE_PROTOCOL: itemsize: int aligned: bool - _DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype) # A protocol for anything with the dtype attribute class _SupportsDType(Protocol[_DType_co]): diff --git a/numpy/typing/tests/data/reveal/nditer.py b/numpy/typing/tests/data/reveal/nditer.py new file mode 100644 index 00000000..de2a4b5e --- /dev/null +++ b/numpy/typing/tests/data/reveal/nditer.py @@ -0,0 +1,19 @@ +import copy +import numpy as np + +nditer_obj: np.nditer + +with nditer_obj as context: + reveal_type(context) # E: numpy.nditer + +reveal_type(len(nditer_obj)) # E: builtins.int +reveal_type(copy.copy(nditer_obj)) # E: numpy.nditer +reveal_type(next(nditer_obj)) # E: Any +reveal_type(iter(nditer_obj)) # E: typing.Iterator[Any] +reveal_type(nditer_obj[1]) # E: Any +reveal_type(nditer_obj[1:5]) # E: Any + +nditer_obj[1] = 1 +nditer_obj[1:5] = 1 +del nditer_obj[1] +del nditer_obj[1:5] diff --git a/numpy/typing/tests/test_typing_extensions.py b/numpy/typing/tests/test_typing_extensions.py new file mode 100644 index 00000000..f59f222f --- /dev/null +++ b/numpy/typing/tests/test_typing_extensions.py @@ -0,0 +1,35 @@ +"""Tests for the optional typing-extensions dependency.""" + +import sys +import textwrap +import subprocess + +CODE = textwrap.dedent(r""" + import sys + import importlib + + assert "typing_extensions" not in sys.modules + assert "numpy.typing" not in sys.modules + + # Importing `typing_extensions` will now raise an `ImportError` + sys.modules["typing_extensions"] = None + assert importlib.import_module("numpy.typing") +""") + + +def test_no_typing_extensions() -> None: + """Import `numpy.typing` in the absence of typing-extensions. + + Notes + ----- + Ideally, we'd just run the normal typing tests in an environment where + typing-extensions is not installed, but unfortunatelly this is currently + impossible as it is an indirect hard dependency of pytest. + + """ + p = subprocess.run([sys.executable, '-c', CODE], capture_output=True) + if p.returncode: + raise AssertionError( + f"Non-zero return code: {p.returncode!r}\n\n{p.stderr.decode()}" + ) + diff --git a/pavement.py b/pavement.py index c7ee8683..572e9d8f 100644 --- a/pavement.py +++ b/pavement.py @@ -38,7 +38,7 @@ from paver.easy import Bunch, options, task, sh #----------------------------------- # Path to the release notes -RELEASE_NOTES = 'doc/source/release/1.21.1-notes.rst' +RELEASE_NOTES = 'doc/source/release/1.21.2-notes.rst' #------------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 14f275e9..941c8fa8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "packaging==20.5; platform_machine=='arm64'", # macos M1 "setuptools<49.2.0", "wheel==0.36.2", - "Cython>=0.29.21,<3.0", # Note: keep in sync with tools/cythonize.py + "Cython>=0.29.24,<3.0", # Note: keep in sync with tools/cythonize.py ] diff --git a/runtests.py b/runtests.py index 452ccbc6..855fd715 100755 --- a/runtests.py +++ b/runtests.py @@ -474,9 +474,24 @@ def build_project(args): '--single-version-externally-managed', '--record=' + dst_dir + 'tmp_install_log.txt'] - from distutils.sysconfig import get_python_lib - site_dir = get_python_lib(prefix=dst_dir, plat_specific=True) - site_dir_noarch = get_python_lib(prefix=dst_dir, plat_specific=False) + py_v_s = sysconfig.get_config_var('py_version_short') + platlibdir = getattr(sys, 'platlibdir', '') # Python3.9+ + site_dir_template = os.path.normpath(sysconfig.get_path( + 'platlib', expand=False + )) + site_dir = site_dir_template.format(platbase=dst_dir, + py_version_short=py_v_s, + platlibdir=platlibdir, + base=dst_dir, + ) + noarch_template = os.path.normpath(sysconfig.get_path( + 'purelib', expand=False + )) + site_dir_noarch = noarch_template.format(base=dst_dir, + py_version_short=py_v_s, + platlibdir=platlibdir, + ) + # easy_install won't install to a path that Python by default cannot see # and isn't on the PYTHONPATH. Plus, it has to exist. if not os.path.exists(site_dir): diff --git a/setup.py b/setup.py index 82661046..ceb99007 100755 --- a/setup.py +++ b/setup.py @@ -93,6 +93,7 @@ Programming Language :: Python :: 3 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 +Programming Language :: Python :: 3.10 Programming Language :: Python :: 3 :: Only Programming Language :: Python :: Implementation :: CPython Topic :: Software Development @@ -405,7 +406,7 @@ def setup_package(): test_suite='pytest', version=versioneer.get_version(), cmdclass=cmdclass, - python_requires='>=3.7', + python_requires='>=3.7,<3.11', zip_safe=False, entry_points={ 'console_scripts': f2py_cmds diff --git a/test_requirements.txt b/test_requirements.txt index e23ec033..1ff36ab7 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,4 @@ -cython==0.29.23 +cython==0.29.24 wheel<0.36.3 setuptools<49.2.0 hypothesis==6.12.0 diff --git a/tools/cythonize.py b/tools/cythonize.py index 06cf54c9..8370574a 100755 --- a/tools/cythonize.py +++ b/tools/cythonize.py @@ -72,7 +72,8 @@ def process_pyx(fromfile, tofile): # other fixes in the 0.29 series that are needed even for earlier # Python versions. # Note: keep in sync with that in pyproject.toml - required_version = LooseVersion('0.29.21') + # Update for Python 3.10 + required_version = LooseVersion('0.29.24') if LooseVersion(cython_version) < required_version: cython_path = Cython.__file__ -- 2.34.1