From dfee8851c65276907eedd084ff40334ea7d46865 Mon Sep 17 00:00:00 2001 From: Max Kellermeier Date: Sun, 2 Aug 2020 18:10:01 +0200 Subject: Tests added according to #14877, obsolete comments removed. --- numpy/lib/tests/test_function_base.py | 18 +++++++++++++++++- 1 file changed, 17 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 eb2fc3311..878fb3de1 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1756,7 +1756,23 @@ class TestUnwrap: assert_array_equal(unwrap([1, 1 + 2 * np.pi]), [1, 1]) # check that unwrap maintains continuity assert_(np.all(diff(unwrap(rand(10) * 100)) < np.pi)) - + + def test_minmax(self): + # check that unwrap removes jumps greater that 255 + assert_array_equal(unwrap([1, 1 + 256], interval_size=255), [1, 2]) + # check that unwrap maintains continuity + assert_(np.all(diff(unwrap(rand(10) * 1000, interval_size=255)) < 255)) + # check simple case + simple_seq = np.array([0, 75, 150, 225, 300]) + wrap_seq = np.mod(simple_seq, 255) + assert_array_equal(unwrap(wrap_seq, interval_size=255), simple_seq) + # check custom discont value + uneven_seq = np.array([0, 75, 150, 225, 300, 430]) + wrap_uneven = np.mod(uneven_seq, 250) + no_discont = unwrap(wrap_uneven, interval_size=250) + assert_array_equal(no_discont, [0, 75, 150, 225, 300, 180]) + sm_discont = unwrap(wrap_uneven, interval_size=250, discont=140) + assert_array_equal(sm_discont, [0, 75, 150, 225, 300, 430]) class TestFilterwindows: -- cgit v1.2.1 From 8cf0872290fa05b6adc18d53e45e121ef9f74bd3 Mon Sep 17 00:00:00 2001 From: scimax Date: Thu, 20 Aug 2020 12:01:53 +0200 Subject: Update numpy/lib/tests/test_function_base.py Co-authored-by: Eric Wieser --- numpy/lib/tests/test_function_base.py | 2 +- 1 file changed, 1 insertion(+), 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 878fb3de1..44ff7ea81 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1757,7 +1757,7 @@ class TestUnwrap: # check that unwrap maintains continuity assert_(np.all(diff(unwrap(rand(10) * 100)) < np.pi)) - def test_minmax(self): + def test_period(self): # check that unwrap removes jumps greater that 255 assert_array_equal(unwrap([1, 1 + 256], interval_size=255), [1, 2]) # check that unwrap maintains continuity -- cgit v1.2.1 From 00dcda244bc1eb58cb3b4f30c7b18a71a8569194 Mon Sep 17 00:00:00 2001 From: Max Kellermeier Date: Fri, 21 Aug 2020 22:55:29 +0200 Subject: Updated incorrect argument in tests. boundary correction for int and float. Co-authored-by: Eric Wieser --- numpy/lib/tests/test_function_base.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 44ff7ea81..2ebde9aec 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1759,20 +1759,21 @@ class TestUnwrap: def test_period(self): # check that unwrap removes jumps greater that 255 - assert_array_equal(unwrap([1, 1 + 256], interval_size=255), [1, 2]) + assert_array_equal(unwrap([1, 1 + 256], period=255), [1, 2]) # check that unwrap maintains continuity - assert_(np.all(diff(unwrap(rand(10) * 1000, interval_size=255)) < 255)) + assert_(np.all(diff(unwrap(rand(10) * 1000, period=255)) < 255)) # check simple case simple_seq = np.array([0, 75, 150, 225, 300]) wrap_seq = np.mod(simple_seq, 255) - assert_array_equal(unwrap(wrap_seq, interval_size=255), simple_seq) + assert_array_equal(unwrap(wrap_seq, period=255), simple_seq) # check custom discont value uneven_seq = np.array([0, 75, 150, 225, 300, 430]) wrap_uneven = np.mod(uneven_seq, 250) - no_discont = unwrap(wrap_uneven, interval_size=250) + no_discont = unwrap(wrap_uneven, period=250) assert_array_equal(no_discont, [0, 75, 150, 225, 300, 180]) - sm_discont = unwrap(wrap_uneven, interval_size=250, discont=140) + sm_discont = unwrap(wrap_uneven, period=250, discont=140) assert_array_equal(sm_discont, [0, 75, 150, 225, 300, 430]) + assert sm_discont.dtype == wrap_uneven.dtype class TestFilterwindows: -- cgit v1.2.1 From e54a06ca81dd93cfda4570ae03740711092e08d3 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Mon, 14 Sep 2020 10:18:55 +0100 Subject: Add missing whitespace --- numpy/lib/tests/test_function_base.py | 1 + 1 file changed, 1 insertion(+) (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 2ebde9aec..f881ddf00 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1775,6 +1775,7 @@ class TestUnwrap: assert_array_equal(sm_discont, [0, 75, 150, 225, 300, 430]) assert sm_discont.dtype == wrap_uneven.dtype + class TestFilterwindows: def test_hanning(self): -- cgit v1.2.1 From aeae93b6c0042f6ed8f45205545985cc194f84f3 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sun, 3 Jan 2021 11:11:15 -0500 Subject: API: make piecewise subclass safe using use zeros_like. Subclass input of piecewise was already respected, so it seems more logical to ensure the output is the same subclass (possibly just an oversight that it was not done before). --- numpy/lib/tests/test_function_base.py | 8 ++++++++ 1 file changed, 8 insertions(+) (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 4c7c0480c..afcb81eff 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2399,6 +2399,14 @@ class TestPiecewise: assert_array_equal(y, np.array([[-1., -1., -1.], [3., 3., 1.]])) + def test_subclasses(self): + class subclass(np.ndarray): + pass + x = np.arange(5.).view(subclass) + r = piecewise(x, [x<2., x>=4], [-1., 1., 0.]) + assert_equal(type(r), subclass) + assert_equal(r, [-1., -1., 0., 0., 1.]) + class TestBincount: -- cgit v1.2.1 From 3cdb33f02298c3544f7a3bc312c42422a2a7b971 Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Wed, 31 Mar 2021 17:11:41 -0400 Subject: Add tests np.meshgrid for higher dimensional grids. --- numpy/lib/tests/test_function_base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (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 afcb81eff..4201afac3 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2219,6 +2219,7 @@ class TestMsort: [0.64864341, 0.79115165, 0.96098397]])) +# Run test using: python3 runtests.py -t numpy.lib.tests.test_function_base class TestMeshgrid: def test_simple(self): @@ -2307,6 +2308,20 @@ class TestMeshgrid: assert_equal(x[0, :], 0) assert_equal(x[1, :], X) + def test_higher_dimensions(self): + a, b, c = np.meshgrid([0], [1, 1], [2, 2]) + assert_equal(a, [[[0, 0]], [[0, 0]]]) + assert_equal(b, [[[1, 1]], [[1, 1]]]) + assert_equal(c, [[[2, 2]], [[2, 2]]]) + + a, b, c, d, e = np.meshgrid(*([0] * i for i in range(1, 6))) + expected_shape = (2, 1, 3, 4, 5) + assert_equal(a.shape, expected_shape) + assert_equal(b.shape, expected_shape) + assert_equal(c.shape, expected_shape) + assert_equal(d.shape, expected_shape) + assert_equal(e.shape, expected_shape) + class TestPiecewise: -- cgit v1.2.1 From 2a880214c0ffb9c21b12ab51fbb364d71aa17cd1 Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Wed, 31 Mar 2021 17:12:37 -0400 Subject: rm comment --- numpy/lib/tests/test_function_base.py | 1 - 1 file changed, 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 4201afac3..8dcbaa034 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2219,7 +2219,6 @@ class TestMsort: [0.64864341, 0.79115165, 0.96098397]])) -# Run test using: python3 runtests.py -t numpy.lib.tests.test_function_base class TestMeshgrid: def test_simple(self): -- cgit v1.2.1 From 9f339758e3faeb447a629d600f7640c8735a6c4a Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Mon, 5 Apr 2021 15:50:16 -0400 Subject: review comments --- numpy/lib/tests/test_function_base.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 8dcbaa034..761ea83a3 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2307,12 +2307,7 @@ class TestMeshgrid: assert_equal(x[0, :], 0) assert_equal(x[1, :], X) - def test_higher_dimensions(self): - a, b, c = np.meshgrid([0], [1, 1], [2, 2]) - assert_equal(a, [[[0, 0]], [[0, 0]]]) - assert_equal(b, [[[1, 1]], [[1, 1]]]) - assert_equal(c, [[[2, 2]], [[2, 2]]]) - + def test_nd_shape(self): a, b, c, d, e = np.meshgrid(*([0] * i for i in range(1, 6))) expected_shape = (2, 1, 3, 4, 5) assert_equal(a.shape, expected_shape) @@ -2321,6 +2316,18 @@ class TestMeshgrid: assert_equal(d.shape, expected_shape) assert_equal(e.shape, expected_shape) + def test_nd_values(self): + a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5]) + assert_equal(a, [[[0, 0, 0]], [[0, 0, 0]]]) + assert_equal(b, [[[1, 1, 1]], [[2, 2, 2]]]) + assert_equal(c, [[[3, 4, 5]], [[3, 4, 5]]]) + + def test_nd_indexing(self): + a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5], indexing='ij') + assert_equal(a, [[[0, 0, 0], [0, 0, 0]]]) + assert_equal(b, [[[1, 1, 1], [2, 2, 2]]]) + assert_equal(c, [[[3, 4, 5], [3, 4, 5]]]) + class TestPiecewise: -- cgit v1.2.1 From 341316d5158477b06f877db60049b0995ab78128 Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Thu, 22 Apr 2021 14:35:43 +0100 Subject: BUG: Prevent nan being used in percentile (gh-18831) Reject NaN as a percentile/quantile value. Previously NaNs could pass the range check `0 <= q <= 1`. closes #18830 --- numpy/lib/tests/test_function_base.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (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 761ea83a3..0b66ccf8c 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2750,6 +2750,10 @@ class TestPercentile: assert_equal(p, Fraction(7, 4)) assert_equal(type(p), Fraction) + p = np.percentile(x, [Fraction(50)]) + assert_equal(p, np.array([Fraction(7, 4)])) + assert_equal(type(p), np.ndarray) + def test_api(self): d = np.ones(5) np.percentile(d, 5, None, None, False) @@ -3144,6 +3148,16 @@ class TestPercentile: assert_equal(np.percentile( a, [0.3, 0.6], (0, 2), interpolation='nearest'), b) + def test_nan_q(self): + # GH18830 + with pytest.raises(ValueError, match="Percentiles must be in"): + np.percentile([1, 2, 3, 4.0], np.nan) + with pytest.raises(ValueError, match="Percentiles must be in"): + np.percentile([1, 2, 3, 4.0], [np.nan]) + q = np.linspace(1.0, 99.0, 16) + q[0] = np.nan + with pytest.raises(ValueError, match="Percentiles must be in"): + np.percentile([1, 2, 3, 4.0], q) class TestQuantile: # most of this is already tested by TestPercentile @@ -3180,6 +3194,14 @@ class TestQuantile: assert_equal(q, Fraction(7, 4)) assert_equal(type(q), Fraction) + q = np.quantile(x, [Fraction(1, 2)]) + assert_equal(q, np.array([Fraction(7, 4)])) + assert_equal(type(q), np.ndarray) + + q = np.quantile(x, [[Fraction(1, 2)]]) + assert_equal(q, np.array([[Fraction(7, 4)]])) + assert_equal(type(q), np.ndarray) + # repeat with integral input but fractional quantile x = np.arange(8) assert_equal(np.quantile(x, Fraction(1, 2)), Fraction(7, 2)) -- cgit v1.2.1