diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-04-26 19:17:08 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-04-26 23:36:07 +0100 |
commit | 05f422827b3317ad3774cbd1859edbf6bc196f75 (patch) | |
tree | e48fcab6686fb77b5c6a6a8bf2970fcbd2c0bfc7 /numpy/lib/tests | |
parent | 628f7b6c8ab806b2ded7ba6b7d802a964395ca91 (diff) | |
download | numpy-05f422827b3317ad3774cbd1859edbf6bc196f75.tar.gz |
BUG: Return scalars from ufunclike objects
No need to reinvent the wheel here - the ufunc machinery will handle the out arguments
Fixes #8993
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_ufunclike.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py index 2f671739e..0b152540f 100644 --- a/numpy/lib/tests/test_ufunclike.py +++ b/numpy/lib/tests/test_ufunclike.py @@ -1,5 +1,6 @@ from __future__ import division, absolute_import, print_function +import numpy as np import numpy.core as nx import numpy.lib.ufunclike as ufl from numpy.testing import ( @@ -62,11 +63,35 @@ class TestUfunclike(TestCase): assert_(isinstance(f, MyArray)) assert_equal(f.metadata, 'foo') + # check 0d arrays don't decay to scalars + m0d = m[0,...] + m0d.metadata = 'bar' + f0d = ufl.fix(m0d) + assert_(isinstance(f0d, MyArray)) + assert_equal(f0d.metadata, 'bar') + def test_deprecated(self): # NumPy 1.13.0, 2017-04-26 assert_warns(DeprecationWarning, ufl.fix, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isposinf, [1, 2], y=nx.empty(2)) assert_warns(DeprecationWarning, ufl.isneginf, [1, 2], y=nx.empty(2)) + def test_scalar(self): + x = np.inf + actual = np.isposinf(x) + expected = np.True_ + assert_equal(actual, expected) + assert_equal(type(actual), type(expected)) + + x = -3.4 + actual = np.fix(x) + expected = np.float64(-3.0) + assert_equal(actual, expected) + assert_equal(type(actual), type(expected)) + + out = np.array(0.0) + actual = np.fix(x, out=out) + assert_(actual is out) + if __name__ == "__main__": run_module_suite() |