Skip to content

Commit

Permalink
Dense Arrays With Negative Domains Can Only Use Full Indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Oct 5, 2023
1 parent 656f54f commit 5145108
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,12 @@ cdef class DenseArrayImpl(Array):
attr_names.extend(self.schema.attr(a).name for a in attrs)

selection = index_as_tuple(selection)

for dim, sel in zip(self.schema.domain, selection):
if dim.domain[0] < 0 and sel != slice(None, None, None):
raise TileDBError("Must use full indexer for arrays containing "
"dimensions with negative integers.")

idx = replace_ellipsis(self.schema.domain.ndim, selection)
idx, drop_axes = replace_scalars_slice(self.schema.domain, idx)
dim_ranges = index_domain_subarray(self, self.schema.domain, idx)
Expand Down Expand Up @@ -2246,6 +2252,11 @@ cdef class DenseArrayImpl(Array):
from .subarray import Subarray
if not self.isopen or self.mode != 'w':
raise TileDBError("DenseArray is not opened for writing")

for dim, sel in zip(self.schema.domain, index_as_tuple(selection)):
if dim.domain[0] < 0 and sel != slice(None, None, None):
raise TileDBError("Must use full indexer for arrays containing "
"dimensions with signed integers.")

domain = self.domain
cdef tuple idx = replace_ellipsis(domain.ndim, index_as_tuple(selection))
Expand Down
57 changes: 57 additions & 0 deletions tiledb/tests/test_libtiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2492,6 +2492,63 @@ def test_index_2d(self):
with self.assertRaises(IndexError):
T[idx]

def test_dense_array_with_negative_domain(self):
path = self.path("test_dense_array_with_negative_domain")
attr = tiledb.Attr(dtype=np.uint8)
dom = tiledb.Domain(tiledb.Dim("X", domain=(-10, 10), dtype=np.int64))
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr])
tiledb.Array.create(path, schema)
data = np.random.randint(10, size=21)

with tiledb.open(path, "w") as A:
with pytest.raises(tiledb.TileDBError):
A[-5:5] = np.random.randint(10, size=11)
with pytest.raises(tiledb.TileDBError):
A[:0] = np.random.randint(10, size=11)
with pytest.raises(tiledb.TileDBError):
A[0:] = np.random.randint(10, size=11)
with pytest.raises(tiledb.TileDBError):
A[0] = np.random.randint(10, size=1)
A[:] = data

with tiledb.open(path, "r") as A:
with pytest.raises(tiledb.TileDBError):
A[-5:5]
with pytest.raises(tiledb.TileDBError):
A[:0]
with pytest.raises(tiledb.TileDBError):
A[0:]
with pytest.raises(tiledb.TileDBError):
A[0]
assert_array_equal(A[:], data[:])

def test_dense_array_with_2d_negative_domain(self):
path = self.path("test_dense_array_with_2d_negative_domain")
attr = tiledb.Attr(dtype=np.uint8)
dim1 = tiledb.Dim("X", domain=(-10, 10), dtype=np.int64)
dim2 = tiledb.Dim("Y", domain=(0, 10), dtype=np.int64)
dom = tiledb.Domain(dim1, dim2)
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr])
tiledb.Array.create(path, schema)
data = np.random.randint(10, size=(21,11))

with tiledb.open(path, "w") as A:
with pytest.raises(tiledb.TileDBError):
A[:,-5:5] = np.random.randint(10, size=11)
with pytest.raises(tiledb.TileDBError):
A[:0, :] = np.random.randint(10, size=11)
with pytest.raises(tiledb.TileDBError):
A[0] = np.random.randint(10, size=1)
A[:] = data

with tiledb.open(path, "r") as A:
with pytest.raises(tiledb.TileDBError):
A[:,-5:5]
with pytest.raises(tiledb.TileDBError):
A[:0, :]
with pytest.raises(tiledb.TileDBError):
A[0]
assert_array_equal(A[:], data[:])

class TestDatetimeSlicing(DiskTestCase):
def test_dense_datetime_vector(self):
Expand Down

0 comments on commit 5145108

Please sign in to comment.