From 11b95d15f10c2bc652ed19d5e27efa0384396cb8 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sat, 6 Jun 2020 15:31:33 -0700 Subject: ENH: add type stubs from numpy-stubs Add the type stubs and tests from numpy-stubs. Things this entails: - Copy over the stubs (numpy/__init__.pyi and numpy/core/_internal.pyi) - The only modification made was removing `ndarray.tostring` since it is deprecated - Update some setup.py files to include pyi files - Move the tests from numpy-stubs/tests into numpy/tests - Skip them if mypy is not installed (planning on setting up CI in a future PR) - Add a mypy.ini; use it to configure mypy in the tests - It tells mypy where to find NumPy in the test env - It ignores internal NumPy type errors (since we only want to consider errors from the tests cases) - Some small edits were made to fix test cases that were emitting deprecation warnings - Add numpy/py.typed so that the types are picked up in an installed version of NumPy --- numpy/tests/pass/ndarray_shape_manipulation.py | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 numpy/tests/pass/ndarray_shape_manipulation.py (limited to 'numpy/tests/pass/ndarray_shape_manipulation.py') diff --git a/numpy/tests/pass/ndarray_shape_manipulation.py b/numpy/tests/pass/ndarray_shape_manipulation.py new file mode 100644 index 000000000..0ca3dff39 --- /dev/null +++ b/numpy/tests/pass/ndarray_shape_manipulation.py @@ -0,0 +1,47 @@ +import numpy as np + +nd1 = np.array([[1, 2], [3, 4]]) + +# reshape +nd1.reshape(4) +nd1.reshape(2, 2) +nd1.reshape((2, 2)) + +nd1.reshape((2, 2), order="C") +nd1.reshape(4, order="C") + +# resize +nd1.resize() +nd1.resize(4) +nd1.resize(2, 2) +nd1.resize((2, 2)) + +nd1.resize((2, 2), refcheck=True) +nd1.resize(4, refcheck=True) + +nd2 = np.array([[1, 2], [3, 4]]) + +# transpose +nd2.transpose() +nd2.transpose(1, 0) +nd2.transpose((1, 0)) + +# swapaxes +nd2.swapaxes(0, 1) + +# flatten +nd2.flatten() +nd2.flatten("C") + +# ravel +nd2.ravel() +nd2.ravel("C") + +# squeeze +nd2.squeeze() + +nd3 = np.array([[1, 2]]) +nd3.squeeze(0) + +nd4 = np.array([[[1, 2]]]) +nd4.squeeze((0, 1)) -- cgit v1.2.1