summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/scalarapi.c9
-rw-r--r--numpy/core/tests/test_regression.py23
2 files changed, 32 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 810029a73..9dfd3c4c8 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -802,6 +802,15 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
return PyErr_NoMemory();
}
vobj->obval = destptr;
+
+ /*
+ * No base available for copyswp and no swap required.
+ * Copy data directly into dest.
+ */
+ if (base == NULL) {
+ memcpy(destptr, data, itemsize);
+ return obj;
+ }
}
}
else {
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 09a035a42..fe2185833 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1186,6 +1186,29 @@ class TestRegression(TestCase):
assert_(arr[0][0] == 'john')
assert_(arr[0][1] == 4)
+ def test_void_scalar_constructor(self):
+ #Issue #1550
+
+ #Create test string data, construct void scalar from data and assert
+ #that void scalar contains original data.
+ test_string = np.array("test")
+ test_string_void_scalar = np.core.multiarray.scalar(
+ np.dtype(("V",test_string.dtype.itemsize)), test_string.tostring())
+
+ assert_(test_string_void_scalar.view(test_string.dtype) == test_string)
+
+ #Create record scalar, construct from data and assert that
+ #reconstructed scalar is correct.
+ test_record = np.ones((), "i,i")
+ test_record_void_scalar = np.core.multiarray.scalar(
+ test_record.dtype, test_record.tostring())
+
+ assert_(test_record_void_scalar == test_record)
+
+ #Test pickle and unpickle of void and record scalars
+ assert_(pickle.loads(pickle.dumps(test_string)) == test_string)
+ assert_(pickle.loads(pickle.dumps(test_record)) == test_record)
+
def test_blasdot_uninitialized_memory(self):
"""Ticket #950"""
for m in [0, 1, 2]: