diff options
author | Stephan Hoyer <shoyer@google.com> | 2019-05-13 08:09:26 -0700 |
---|---|---|
committer | Stephan Hoyer <shoyer@google.com> | 2019-05-13 08:09:26 -0700 |
commit | 07452c86c78a1cf213a764d17f060b4887ec3681 (patch) | |
tree | 12c7ae7b14552bd28334277e7e244b603ca4300a /numpy/lib/tests/test_function_base.py | |
parent | 804f71bb42fef775a85a52366dc4bd1a22c130a8 (diff) | |
parent | 4ad33d21b1a30f931e23307e9f9355b70f633bed (diff) | |
download | numpy-07452c86c78a1cf213a764d17f060b4887ec3681.tar.gz |
Merge branch 'master' into implement-numpy-implementation
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index e2c24a123..a3d4c6efb 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -5,6 +5,7 @@ import warnings import sys import decimal import types +from fractions import Fraction import pytest import numpy as np @@ -695,6 +696,9 @@ class TestDiff(object): assert_raises(np.AxisError, diff, x, axis=3) assert_raises(np.AxisError, diff, x, axis=-4) + x = np.array(1.11111111111, np.float64) + assert_raises(ValueError, diff, x) + def test_nd(self): x = 20 * rand(10, 20, 30) out1 = x[:, :, 1:] - x[:, :, :-1] @@ -944,7 +948,7 @@ class TestGradient(object): assert_equal(type(out), type(x)) # And make sure that the output and input don't have aliased mask # arrays - assert_(x.mask is not out.mask) + assert_(x._mask is not out._mask) # Also check that edge_order=2 doesn't alter the original mask x2 = np.ma.arange(5) x2[2] = np.ma.masked @@ -2508,6 +2512,21 @@ class TestPercentile(object): assert_equal(np.percentile(x, 0), np.nan) assert_equal(np.percentile(x, 0, interpolation='nearest'), np.nan) + def test_fraction(self): + x = [Fraction(i, 2) for i in np.arange(8)] + + p = np.percentile(x, Fraction(0)) + assert_equal(p, Fraction(0)) + assert_equal(type(p), Fraction) + + p = np.percentile(x, Fraction(100)) + assert_equal(p, Fraction(7, 2)) + assert_equal(type(p), Fraction) + + p = np.percentile(x, Fraction(50)) + assert_equal(p, Fraction(7, 4)) + assert_equal(type(p), Fraction) + def test_api(self): d = np.ones(5) np.percentile(d, 5, None, None, False) @@ -2912,6 +2931,26 @@ class TestQuantile(object): assert_equal(np.quantile(x, 1), 3.5) assert_equal(np.quantile(x, 0.5), 1.75) + def test_fraction(self): + # fractional input, integral quantile + x = [Fraction(i, 2) for i in np.arange(8)] + + q = np.quantile(x, 0) + assert_equal(q, 0) + assert_equal(type(q), Fraction) + + q = np.quantile(x, 1) + assert_equal(q, Fraction(7, 2)) + assert_equal(type(q), Fraction) + + q = np.quantile(x, Fraction(1, 2)) + assert_equal(q, Fraction(7, 4)) + assert_equal(type(q), Fraction) + + # repeat with integral input but fractional quantile + x = np.arange(8) + assert_equal(np.quantile(x, Fraction(1, 2)), Fraction(7, 2)) + def test_no_p_overwrite(self): # this is worth retesting, because quantile does not make a copy p0 = np.array([0, 0.75, 0.25, 0.5, 1.0]) |