Skip to content

Commit f7145ed

Browse files
authored
Dense Array [:] Returns Nonempty Domain Only (#1199)
1 parent d53c981 commit f7145ed

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
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+
## API Changes
7+
* 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)
8+
69
# TileDB-Py 0.16.1 Release Notes
710

811
## TileDB Embedded updates:

tiledb/libtiledb.pyx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ def replace_scalars_slice(dom: Domain, idx: tuple):
25252525
return tuple(new_idx), tuple(drop_axes)
25262526

25272527

2528-
def index_domain_subarray(array: Array, dom: Domain, idx: tuple):
2528+
def index_domain_subarray(array: Array, dom: Domain, idx: tuple, read_array: bool = False):
25292529
"""
25302530
Return a numpy array representation of the tiledb subarray buffer
25312531
for a given domain and tuple of index slices
@@ -2543,9 +2543,17 @@ def index_domain_subarray(array: Array, dom: Domain, idx: tuple):
25432543

25442544
if np.issubdtype(dim_dtype, np.unicode_) or np.issubdtype(dim_dtype, np.bytes_):
25452545
ned = array.nonempty_domain()
2546-
(dim_lb, dim_ub) = ned[r] if ned else (None, None)
2546+
(dim_lb, dim_ub) = ned[r] if ned is not None else (None, None)
25472547
else:
2548-
(dim_lb, dim_ub) = dim.domain
2548+
if read_array:
2549+
ned = array.nonempty_domain()
2550+
(dim_lb, dim_ub) = (
2551+
np.array(ned[r], dim_dtype)
2552+
if ned is not None
2553+
else dim.domain
2554+
)
2555+
else:
2556+
(dim_lb, dim_ub) = dim.domain
25492557

25502558

25512559
dim_slice = idx[r]
@@ -4437,7 +4445,7 @@ cdef class DenseArrayImpl(Array):
44374445
selection = index_as_tuple(selection)
44384446
idx = replace_ellipsis(self.schema.domain.ndim, selection)
44394447
idx, drop_axes = replace_scalars_slice(self.schema.domain, idx)
4440-
subarray = index_domain_subarray(self, self.schema.domain, idx)
4448+
subarray = index_domain_subarray(self, self.schema.domain, idx, True)
44414449
# Note: we included dims (coords) above to match existing semantics
44424450
out = self._read_dense_subarray(subarray, attr_names, attr_cond, layout,
44434451
coords)

tiledb/tests/test_libtiledb.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,21 @@ def test_reopen_dense_array(self):
18011801

18021802
T.close()
18031803

1804+
def test_writing_partial_dense_array(self):
1805+
uri = self.path("test_writing_partial_dense_array")
1806+
1807+
dom = tiledb.Domain(tiledb.Dim(domain=(0, 1000), tile=1000, dtype=np.int64))
1808+
attr = tiledb.Attr(name="rows", dtype=np.int64)
1809+
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[attr])
1810+
tiledb.Array.create(uri, schema)
1811+
1812+
with tiledb.open(uri, "w") as A:
1813+
A[0:1000] = np.arange(1000)
1814+
1815+
with tiledb.open(uri) as A:
1816+
ned = A.nonempty_domain()[0]
1817+
assert len(A[:]["rows"]) == ned[1] - ned[0] + 1
1818+
18041819

18051820
class TestVarlen(DiskTestCase):
18061821
def test_varlen_write_bytes(self):

0 commit comments

Comments
 (0)