Skip to content

Commit bd12bb9

Browse files
authored
Index out of bounds when nonempty domain is empty string (#1182)
* Add Test to Ensure Empty String's NED is `(None, None)`
1 parent bc0ed54 commit bd12bb9

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Improvements
44
* `setup.py` retrieves core version by using `ctypes` to call `tiledb_version` rather than parsing `tiledb_version.h` [#1191](https://github.com/TileDB-Inc/TileDB-Py/pull/1191)
55

6+
## Bug Fixes
7+
* Set nonempty domain to `(None, None)` for empty string [#1182](https://github.com/TileDB-Inc/TileDB-Py/pull/1182)
8+
69
## API Changes
710
* Support `QueryCondition` for dense arrays [#1198](https://github.com/TileDB-Inc/TileDB-Py/pull/1198)
811
* Querying dense array with `[:]` returns shape that matches nonempty domain, consistent with `.df[:]` and `.multi_index[:]` [#1199](https://github.com/TileDB-Inc/TileDB-Py/pull/1199)

tiledb/libtiledb.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ cdef class Array(object):
38373837
continue
38383838

38393839
buf_dtype = 'S'
3840-
start_buf = np.empty(end_size, 'S' + str(start_size))
3840+
start_buf = np.empty(start_size, 'S' + str(start_size))
38413841
end_buf = np.empty(end_size, 'S' + str(end_size))
38423842
start_buf_ptr = np.PyArray_DATA(start_buf)
38433843
end_buf_ptr = np.PyArray_DATA(end_buf)
@@ -3854,7 +3854,11 @@ cdef class Array(object):
38543854
_raise_ctx_err(ctx_ptr, rc)
38553855
if is_empty:
38563856
return None
3857-
results.append((start_buf.item(0), end_buf.item(0)))
3857+
3858+
if start_size > 0 and end_size > 0:
3859+
results.append((start_buf.item(0), end_buf.item(0)))
3860+
else:
3861+
results.append((None, None))
38583862
else:
38593863
rc = tiledb_array_get_non_empty_domain_from_index(
38603864
ctx_ptr, array_ptr, dim_idx, start_buf_ptr, &is_empty

tiledb/tests/test_libtiledb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pickle
66
import random
77
import re
8+
from tkinter import NONE
89
import urllib
910
import subprocess
1011
import sys
@@ -1022,6 +1023,21 @@ def test_nonempty_domain_scalar(self):
10221023
assert isinstance(ned[0][0], int)
10231024
assert isinstance(ned[0][1], int)
10241025

1026+
def test_nonempty_domain_empty_string(self):
1027+
uri = self.path("test_nonempty_domain_empty_string")
1028+
dims = [tiledb.Dim(dtype="ascii")]
1029+
schema = tiledb.ArraySchema(tiledb.Domain(dims), sparse=True)
1030+
tiledb.Array.create(uri, schema)
1031+
1032+
with tiledb.open(uri, "r") as A:
1033+
assert_array_equal(A.nonempty_domain(), ((None, None),))
1034+
1035+
with tiledb.open(uri, "w") as A:
1036+
A[""] = None
1037+
1038+
with tiledb.open(uri, "r") as A:
1039+
assert_array_equal(A.nonempty_domain(), ((b"", b""),))
1040+
10251041
def test_create_array_overwrite(self):
10261042
uri = self.path("test_create_array_overwrite")
10271043
dims = tiledb.Dim(domain=(0, 10), dtype=np.int64)

0 commit comments

Comments
 (0)