Skip to content

Commit

Permalink
Fix varlen tests on older NumPy versions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ihnorton committed May 17, 2019
1 parent 068dc28 commit b099a9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<PyTypeObject*> np.ndarray,
el_dtype.base, 1, dims, NULL,
el_ptr,
np.NPY_ENSURECOPY, <object> NULL)
0, <object> NULL))

# set the output object
out_flat[el] = newobj
Expand Down
3 changes: 1 addition & 2 deletions tiledb/tests/test_libtiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_)))

Expand Down

0 comments on commit b099a9d

Please sign in to comment.