Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dense Arrays With Negative Domains Can Only Use Full Indexer #1841

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions tiledb/tests/test_libtiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2492,6 +2492,64 @@ 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