summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
authorczgdp1807 <gdp.1807@gmail.com>2021-06-08 14:56:41 +0530
committerczgdp1807 <gdp.1807@gmail.com>2021-06-08 14:56:41 +0530
commite828f1569dd65cb8a93a619fc89edec582c744cc (patch)
tree9d806619ee60a0c2a16dad55347cf180181ea1da /numpy/core/tests
parentf2e7a818561c59e014d0627a187ae359dafe7a37 (diff)
downloadnumpy-e828f1569dd65cb8a93a619fc89edec582c744cc.tar.gz
Add tests for scalars
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/test_multiarray.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index ba8caddda..8fd7ccf4e 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -7750,6 +7750,17 @@ class TestArrayCreationCopyArgument(object):
true_vals = [True, np.CopyMode.ALWAYS, np.True_]
false_vals = [False, np.CopyMode.IF_NEEDED, np.False_]
+ def test_scalars(self):
+ # Test both numpy and python scalars
+ for dtype in np.typecodes["All"]:
+ arr = np.zeros((), dtype=dtype)
+ scalar = arr[()]
+ pyscalar = arr.item(0)
+
+ # Test never-copy raises error:
+ assert_raises(ValueError, np.array, scalar, copy=np.CopyMode.NEVER)
+ assert_raises(ValueError, np.array, pyscalar, copy=np.CopyMode.NEVER)
+
def test_compatible_cast(self):
# Some types are compatible even though they are different, no