From 8eccbf7df2f564e23c1bf7c9f5ee08e4b0dc6a36 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sun, 25 Feb 2018 11:28:31 -0800 Subject: BUG/MAINT: Remove special handling of 0d arrays and scalars in interp These are now handled generically by the underlying C function This fixes the period argument for 0d arrays. Now never returns a pure-python scalar, which matches the behaviour of most of numpy. Rework of b66a200a4a1e98f1955c8a774e4ebfb4588dab5b --- numpy/lib/tests/test_function_base.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index dc5fe3397..49b450175 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2252,8 +2252,17 @@ class TestInterp(object): y = np.linspace(0, 1, 5) x0 = np.array(.3) assert_almost_equal(np.interp(x0, x, y), x0) - x0 = np.array(.3, dtype=object) - assert_almost_equal(np.interp(x0, x, y), .3) + + xp = np.array([0, 2, 4]) + fp = np.array([1, -1, 1]) + + actual = np.interp(np.array(1), xp, fp) + assert_equal(actual, 0) + assert_(isinstance(actual, np.float64)) + + actual = np.interp(np.array(4.5), xp, fp, period=4) + assert_equal(actual, 0.5) + assert_(isinstance(actual, np.float64)) def test_if_len_x_is_small(self): xp = np.arange(0, 10, 0.0001) -- cgit v1.2.1 From 018dfbcaa69d8bcda4d909be11a65a188cf5d1dd Mon Sep 17 00:00:00 2001 From: David Freese Date: Sun, 25 Feb 2018 20:09:15 -0800 Subject: BUG: fix complex casting error in cov with aweights When using cov with a complex input and with aweights specified, cov will error as a result of trying to cast a complex value into a float64. This comes about since average is used to calculate the sum of the weights from aweights. average returns the sum of weights as the same type as its result, not the weights type. For a complex input m, and any type for aweights, this would result in a complex value for fact. It appears the primary purpose of np.float64(fact) is to provide a NaN value from the divide when fact is an integer zero. This has been replaced by using numpy.divide to replicate the same behavior, but to also handle complex types. --- numpy/lib/tests/test_function_base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index dc5fe3397..89bc02fb7 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1752,7 +1752,9 @@ class TestCov(object): def test_complex(self): x = np.array([[1, 2, 3], [1j, 2j, 3j]]) - assert_allclose(cov(x), np.array([[1., -1.j], [1.j, 1.]])) + res = np.array([[1., -1.j], [1.j, 1.]]) + assert_allclose(cov(x), res) + assert_allclose(cov(x, aweights=np.ones(3)), res) def test_xy(self): x = np.array([[1, 2, 3]]) -- cgit v1.2.1 From e97de95d4cae6805ed6c258655e7492a5f2ce863 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 12 Mar 2018 22:47:12 +0000 Subject: Fix low-hanging Pypy compatibility issues (#10737) * TST: skip refcount-requiring tests if sys.refcount is missing * ENH: io: add refcheck=False to a safe .resize() call The array is allocated immediately above, and the resize always succeeds so it is not necessary to check it. Fixes Pypy compatibility. * TST: remove unused code * TST: factor skipif(not HAS_REFCOUNT) into a separate decorator --- numpy/lib/tests/test_function_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 49b450175..2b1ac1cc0 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -11,7 +11,7 @@ from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_array_max_ulp, assert_warns, assert_raises_regex, - dec, suppress_warnings, HAS_REFCOUNT, + dec, suppress_warnings, ) import numpy.lib.function_base as nfb from numpy.random import rand @@ -2141,7 +2141,7 @@ class TestBincount(object): "must not be negative", lambda: np.bincount(x, minlength=-1)) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_dtype_reference_leaks(self): # gh-6805 intp_refcount = sys.getrefcount(np.dtype(np.intp)) -- cgit v1.2.1 From 7e5a41de9fab731e27a761c01302a0a93e2d1070 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Sun, 25 Mar 2018 12:34:16 -0600 Subject: TST: Switch to using pytest markers Use standard pytest markers everywhere in the numpy tests. At this point there should be no nose dependency. However, nose is required to test the legacy decorators if so desired. At this point, numpy test cannot be run in the way with runtests, rather installed numpy can be tested with `pytest --pyargs numpy` as long as that is not run from the repo. Run it from the tools directory or some such. --- numpy/lib/tests/test_function_base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index c28257c6d..2ea2dbc56 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -4,6 +4,7 @@ import operator import warnings import sys import decimal +import pytest import numpy as np from numpy import ma @@ -11,7 +12,7 @@ from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_array_max_ulp, assert_warns, assert_raises_regex, - dec, suppress_warnings, + suppress_warnings, HAS_REFCOUNT, ) import numpy.lib.function_base as nfb from numpy.random import rand @@ -2143,7 +2144,7 @@ class TestBincount(object): "must not be negative", lambda: np.bincount(x, minlength=-1)) - @dec._needs_refcount + @pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts") def test_dtype_reference_leaks(self): # gh-6805 intp_refcount = sys.getrefcount(np.dtype(np.intp)) @@ -2987,7 +2988,7 @@ class TestAdd_newdoc_ufunc(object): class TestAdd_newdoc(object): - @dec.skipif(sys.flags.optimize == 2) + @pytest.mark.skipif(sys.flags.optimize == 2, reason="Python running -OO") def test_add_doc(self): # test np.add_newdoc tgt = "Current flat index into the array." -- cgit v1.2.1 From 7bf0564f87511d9e7b6287b3eec0857d0d7742df Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 4 Apr 2018 10:33:07 -0600 Subject: MAINT: Remove all uses of run_module_suite. That function is nose specific and has not worked since `__init__` files were added to the tests directories. --- numpy/lib/tests/test_function_base.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 2ea2dbc56..0a4c7c370 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -9,11 +9,11 @@ import pytest import numpy as np from numpy import ma from numpy.testing import ( - run_module_suite, assert_, assert_equal, assert_array_equal, - assert_almost_equal, assert_array_almost_equal, assert_raises, - assert_allclose, assert_array_max_ulp, assert_warns, assert_raises_regex, - suppress_warnings, HAS_REFCOUNT, -) + assert_, assert_equal, assert_array_equal, assert_almost_equal, + assert_array_almost_equal, assert_raises, assert_allclose, + assert_array_max_ulp, assert_warns, assert_raises_regex, suppress_warnings, + HAS_REFCOUNT, + ) import numpy.lib.function_base as nfb from numpy.random import rand from numpy.lib import ( @@ -22,7 +22,7 @@ from numpy.lib import ( histogram, histogramdd, i0, insert, interp, kaiser, meshgrid, msort, piecewise, place, rot90, select, setxor1d, sinc, split, trapz, trim_zeros, unwrap, unique, vectorize -) + ) from numpy.compat import long @@ -2995,7 +2995,3 @@ class TestAdd_newdoc(object): assert_equal(np.core.flatiter.index.__doc__[:len(tgt)], tgt) assert_(len(np.core.ufunc.identity.__doc__) > 300) assert_(len(np.lib.index_tricks.mgrid.__doc__) > 300) - - -if __name__ == "__main__": - run_module_suite() -- cgit v1.2.1 From 9d1d44fc120c451a4925720027e85c70e13c26f2 Mon Sep 17 00:00:00 2001 From: Junjie Bai Date: Tue, 10 Apr 2018 01:24:35 -0700 Subject: ENH: Extend np.flip to work over multiple axes Closes #10847 --- numpy/lib/tests/test_function_base.py | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 0a4c7c370..6653b5ba1 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -104,9 +104,10 @@ class TestRot90(object): class TestFlip(object): def test_axes(self): - assert_raises(ValueError, np.flip, np.ones(4), axis=1) - assert_raises(ValueError, np.flip, np.ones((4, 4)), axis=2) - assert_raises(ValueError, np.flip, np.ones((4, 4)), axis=-3) + assert_raises(np.AxisError, np.flip, np.ones(4), axis=1) + assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=2) + assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=-3) + assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=(0, 3)) def test_basic_lr(self): a = get_mat(4) @@ -173,6 +174,35 @@ class TestFlip(object): assert_equal(np.flip(a, i), np.flipud(a.swapaxes(0, i)).swapaxes(i, 0)) + def test_default_axis(self): + a = np.array([[1, 2, 3], + [4, 5, 6]]) + b = np.array([[6, 5, 4], + [3, 2, 1]]) + assert_equal(np.flip(a), b) + + def test_multiple_axes(self): + a = np.array([[[0, 1], + [2, 3]], + [[4, 5], + [6, 7]]]) + + assert_equal(np.flip(a, axis=()), a) + + b = np.array([[[5, 4], + [7, 6]], + [[1, 0], + [3, 2]]]) + + assert_equal(np.flip(a, axis=(0, 2)), b) + + c = np.array([[[3, 2], + [1, 0]], + [[7, 6], + [5, 4]]]) + + assert_equal(np.flip(a, axis=(1, 2)), c) + class TestAny(object): -- cgit v1.2.1