Skip to content

Commit 04cb673

Browse files
authored
Add read_subarray and write_subarray methods to arrays (#1824)
Add read_subarray and write_subarray methods to arrays
1 parent d4fc257 commit 04cb673

File tree

8 files changed

+1050
-97
lines changed

8 files changed

+1050
-97
lines changed

tiledb/cc/subarray.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ void init_subarray(py::module &m) {
632632
})
633633
#endif
634634

635+
.def("_has_label_range",
636+
[](Subarray &subarray, const Context &ctx, uint32_t dim_idx) {
637+
return has_label_range(ctx, subarray, dim_idx);
638+
})
639+
635640
.def("copy_ranges",
636641
[](Subarray &subarray, Subarray &original, py::iterable dims) {
637642
for (auto dim_idx : dims) {
@@ -671,10 +676,6 @@ void init_subarray(py::module &m) {
671676
static_cast<py::ssize_t *>(shape_result.ptr);
672677
// Set size for each dimension.
673678
for (uint32_t dim_idx{0}; dim_idx < ndim; ++dim_idx) {
674-
if (has_label_range(ctx, subarray, dim_idx)) {
675-
throw TileDBPyError(
676-
"Cannot get the shape of a subarray with label ranges.");
677-
}
678679
shape_ptr[dim_idx] = length_ranges(subarray, dim_idx);
679680
}
680681
return shape;

tiledb/indexing.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cdef class DomainIndexer(object):
3232
self.array_ref = weakref.ref(array)
3333
self.schema = array.schema
3434
self.query = query
35-
35+
3636
@property
3737
def schema(self):
3838
return self.array.array_ref().schema
@@ -44,6 +44,7 @@ cdef class DomainIndexer(object):
4444
return self.array_ref()
4545

4646
def __getitem__(self, object idx):
47+
from .subarray import Subarray # prevent circular import
4748
# implements domain-based indexing: slice by domain coordinates, not 0-based python indexing
4849

4950
schema = self.array.schema
@@ -68,11 +69,13 @@ cdef class DomainIndexer(object):
6869
else:
6970
new_idx.append(dim_idx)
7071

71-
subarray = list()
72+
dim_ranges = list()
7273

7374
for i, subidx in enumerate(new_idx):
7475
assert isinstance(subidx, slice)
75-
subarray.append((subidx.start, subidx.stop))
76+
dim_ranges.append((subidx.start, subidx.stop))
77+
subarray = Subarray(self.array)
78+
subarray.add_ranges([list([x]) for x in dim_ranges])
7679

7780
attr_names = list(schema.attr(i).name for i in range(schema.nattr))
7881
attr_cond = None

tiledb/libtiledb.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,10 +1198,10 @@ cdef class Array(object):
11981198
cdef _ndarray_is_varlen(self, np.ndarray array)
11991199

12001200
cdef class SparseArrayImpl(Array):
1201-
cdef _read_sparse_subarray(self, list subarray, list attr_names, object cond, tiledb_layout_t layout)
1201+
cdef _read_sparse_subarray(self, object subarray, list attr_names, object cond, tiledb_layout_t layout)
12021202

12031203
cdef class DenseArrayImpl(Array):
1204-
cdef _read_dense_subarray(self, list subarray, list attr_names, object cond, tiledb_layout_t layout, bint include_coords)
1204+
cdef _read_dense_subarray(self, object subarray, list attr_names, object cond, tiledb_layout_t layout, bint include_coords)
12051205

12061206
cdef class Query(object):
12071207
cdef Array array

0 commit comments

Comments
 (0)