summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-07 12:20:31 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-04-07 12:20:31 -0700
commit756d13449aa3d0b6be4439e87c5cb520c419d30b (patch)
tree0f824a05b0e8cfd61d8c74c03bf74a07e7d96e6a
parentef76d4928ea1591d382fceaa416678907ea76098 (diff)
parenta0a2e3cda794d3119f8534c13d031e0de5130b3f (diff)
downloadnumpy-756d13449aa3d0b6be4439e87c5cb520c419d30b.tar.gz
Merge pull request #3188 from asford/master
Fixing numpy.void pickling.
-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]: