From b099a9df619b61a24ed41c434f3763c75e7fb655 Mon Sep 17 00:00:00 2001 From: Isaiah Norton Date: Fri, 17 May 2019 09:55:18 -0400 Subject: [PATCH] Fix varlen tests on older NumPy versions. Older NumPy versions don't respect NPY_ENSURECOPY in some circumstances, which means that the data in the varlen result array is no longer valid after the underlying buffer is freed. --- tiledb/libtiledb.pyx | 4 ++-- tiledb/tests/test_libtiledb.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 070a7972b6..937d0bb9c2 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -3823,11 +3823,11 @@ cdef class Array(object): # note: must not divide by itemsize for a string, because it may be zero (e.g 'S0') dims[0] = el_bytelen / el_dtype.base.itemsize newobj = \ - PyArray_NewFromDescr( + np.copy(PyArray_NewFromDescr( np.ndarray, el_dtype.base, 1, dims, NULL, el_ptr, - np.NPY_ENSURECOPY, NULL) + 0, NULL)) # set the output object out_flat[el] = newobj diff --git a/tiledb/tests/test_libtiledb.py b/tiledb/tests/test_libtiledb.py index e12b304c35..721485ebe1 100644 --- a/tiledb/tests/test_libtiledb.py +++ b/tiledb/tests/test_libtiledb.py @@ -1046,14 +1046,13 @@ def test_varlen_write_floats(self): att = tiledb.Attr(dtype=np.float64, var=True, ctx=ctx) schema = tiledb.ArraySchema(dom, (att,), ctx=ctx) - tiledb.DenseArray.create(self.path("foo"), schema) with tiledb.DenseArray(self.path("foo"), mode='w', ctx=ctx) as T: T[:] = A with tiledb.DenseArray(self.path("foo"), mode='r', ctx=ctx) as T: T_ = T[:] - self.assertEqual(len(A), len(T)) + self.assertEqual(len(A), len(T_)) # can't use assert_array_equal w/ np.object array self.assertTrue(all(np.array_equal(x,A[i]) for i,x in enumerate(T_)))