@@ -1511,8 +1511,8 @@ cdef class Array(object):
1511
1511
1512
1512
** Example **
1513
1513
1514
- >>> import tiledb, numpy as np
1515
- >>>
1514
+ >>> import tiledb, numpy as np, tempfile
1515
+ >>> from collections import OrderedDict
1516
1516
>>> dim1 = tiledb.Dim("d1", domain=(1, 4))
1517
1517
>>> dim2 = tiledb.Dim("d2", domain=(1, 3))
1518
1518
>>> dom = tiledb.Domain(dim1, dim2)
@@ -1537,21 +1537,30 @@ cdef class Array(object):
1537
1537
... A[:] = {"a1": a1_data, "l1": l1_data, "l2": l2_data, "l3": l3_data}
1538
1538
...
1539
1539
... with tiledb.open(tmp, "r") as A:
1540
- ... A.label_index(["l1"])[3:4] # doctest: +ELLIPSIS
1541
- ... A.label_index(["l1", "l3"])[2, 0.5:1.0] # doctest: +ELLIPSIS
1542
- ... A.label_index(["l2"])[:, -1:0] # doctest: +ELLIPSIS
1543
- ... A.label_index(["l3"])[:, 0.5:1.0] # doctest: +ELLIPSIS
1544
- OrderedDict(...'l1'... array([4, 3])..., ...'a1'... array([[1, 2, 3],
1545
- [4, 5, 6]])...)
1546
- OrderedDict(...'l3'... array([0.5, 1. ])..., ...'l1'... array([2])..., ...'a1'... array([[8, 9]])...)
1547
- OrderedDict(...'l2'... array([-1, 0])..., ...'a1'... array([[ 1, 2],
1548
- [ 4, 5],
1549
- [ 7, 8],
1550
- [10, 11]])...)
1551
- OrderedDict(...'l3'... array([0.5, 1. ])..., ...'a1'... array([[ 2, 3],
1552
- [ 5, 6],
1553
- [ 8, 9],
1554
- [11, 12]])...)
1540
+ ... np.testing.assert_equal(
1541
+ ... A.label_index(["l1"])[3:4],
1542
+ ... OrderedDict({"l1": [4, 3], "a1": [[1, 2, 3], [4, 5, 6]]}),
1543
+ ... )
1544
+ ... np.testing.assert_equal(
1545
+ ... A.label_index(["l1", "l3"])[2, 0.5:1.0],
1546
+ ... OrderedDict(
1547
+ ... {"l3": [0.5, 1.0], "l1": [2], "a1": [[8, 9]]}
1548
+ ... ),
1549
+ ... )
1550
+ ... np.testing.assert_equal(
1551
+ ... A.label_index(["l2"])[:, -1:0],
1552
+ ... OrderedDict(
1553
+ ... {"l2": [-1, 0],
1554
+ ... "a1": [[1, 2], [4, 5], [7, 8], [10, 11]]},
1555
+ ... ),
1556
+ ... )
1557
+ ... np.testing.assert_equal(
1558
+ ... A.label_index(["l3"])[:, 0.5:1.0],
1559
+ ... OrderedDict(
1560
+ ... {"l3": [0.5, 1.],
1561
+ ... "a1": [[2, 3], [5, 6], [8, 9], [11, 12]]},
1562
+ ... ),
1563
+ ... )
1555
1564
1556
1565
:param labels: List of labels to use when querying. Can only use at most one
1557
1566
label per dimension.
@@ -1560,6 +1569,7 @@ cdef class Array(object):
1560
1569
query the array on the corresponding dimension.
1561
1570
:returns: dict of {'label/attribute': result}.
1562
1571
:raises: :py:exc:`tiledb.TileDBError`
1572
+
1563
1573
"""
1564
1574
# Delayed to avoid circular import
1565
1575
from .multirange_indexing import LabelIndexer
@@ -2144,8 +2154,7 @@ cdef class DenseArrayImpl(Array):
2144
2154
def query (self , attrs = None , attr_cond = None , cond = None , dims = None ,
2145
2155
coords = False , order = 'C' , use_arrow = None , return_arrow = False ,
2146
2156
return_incomplete = False ):
2147
- """
2148
- Construct a proxy Query object for easy subarray queries of cells
2157
+ """Construct a proxy Query object for easy subarray queries of cells
2149
2158
for an item or region of the array across one or more attributes.
2150
2159
2151
2160
Optionally subselect over attributes, return dense result coordinate values,
@@ -2188,8 +2197,8 @@ cdef class DenseArrayImpl(Array):
2188
2197
... A[0:10] = {"a1": np.zeros((10)), "a2": np.ones((10))}
2189
2198
... with tiledb.DenseArray(tmp + "/array", mode='r') as A:
2190
2199
... # Access specific attributes individually.
2191
- ... A.query(attrs=("a1",))[0:5] # doctest: +ELLIPSIS
2192
- OrderedDict( ...'a1'... array([0, 0, 0, 0, 0])... )
2200
+ ... np.testing.assert_equal( A.query(attrs=("a1",))[0:5],
2201
+ ... {"a1": np.zeros(5)} )
2193
2202
2194
2203
"""
2195
2204
if not self .isopen or self .mode != 'r' :
@@ -2243,8 +2252,8 @@ cdef class DenseArrayImpl(Array):
2243
2252
... A[0:10] = {"a1": np.zeros((10)), "a2": np.ones((10))}
2244
2253
... with tiledb.DenseArray(tmp + "/array", mode='r') as A:
2245
2254
... # A[0:5], attribute a1, row-major without coordinates
2246
- ... A.subarray((slice(0, 5),), attrs=("a1",), coords=False, order='C') # doctest: +ELLIPSIS
2247
- OrderedDict( ...'a1'... array([0, 0, 0, 0, 0])... )
2255
+ ... np.testing.assert_equal( A.subarray((slice(0, 5),), attrs=("a1",), coords=False, order='C'),
2256
+ ... OrderedDict({'a1': np.zeros(5)}) )
2248
2257
2249
2258
"""
2250
2259
from .subarray import Subarray
@@ -3164,6 +3173,7 @@ cdef class SparseArrayImpl(Array):
3164
3173
**Example:**
3165
3174
3166
3175
>>> import tiledb, numpy as np, tempfile
3176
+ >>> from collections import OrderedDict
3167
3177
>>> # Write to multi-attribute 2D array
3168
3178
>>> with tempfile.TemporaryDirectory() as tmp:
3169
3179
... dom = tiledb.Domain(
@@ -3181,10 +3191,12 @@ cdef class SparseArrayImpl(Array):
3181
3191
... "a2": np.array([3, 4])}
3182
3192
... with tiledb.SparseArray(tmp + "/array", mode='r') as A:
3183
3193
... # Return an OrderedDict with values and coordinates
3184
- ... A[0:3, 0:10] # doctest: +ELLIPSIS
3194
+ ... np.testing.assert_equal(A[0:3, 0:10], OrderedDict({'a1': np.array([1, 2]),
3195
+ ... 'a2': np.array([3, 4]), 'y': np.array([0, 2], dtype=np.uint64),
3196
+ ... 'x': np.array([0, 3], dtype=np.uint64)}))
3185
3197
... # Return just the "x" coordinates values
3186
- ... A[0:3, 0:10]["x"] # doctest: +ELLIPSIS
3187
- OrderedDict(...'a1'... array([1, 2])..., ...'a2'... array([3, 4])..., ...'y'... array([ 0, 2], dtype=uint64)..., ...'x'... array([0, 3], dtype=uint64)... )
3198
+ ... A[0:3, 0:10]["x"]
3199
+ array([0, 3], dtype=uint64)
3188
3200
3189
3201
With a floating-point array domain, index bounds are inclusive, e.g.:
3190
3202
@@ -3241,6 +3253,7 @@ cdef class SparseArrayImpl(Array):
3241
3253
**Example:**
3242
3254
3243
3255
>>> import tiledb, numpy as np, tempfile
3256
+ >>> from collections import OrderedDict
3244
3257
>>> # Write to multi-attribute 2D array
3245
3258
>>> with tempfile.TemporaryDirectory() as tmp:
3246
3259
... dom = tiledb.Domain(
@@ -3257,8 +3270,8 @@ cdef class SparseArrayImpl(Array):
3257
3270
... A[I, J] = {"a1": np.array([1, 2]),
3258
3271
... "a2": np.array([3, 4])}
3259
3272
... with tiledb.SparseArray(tmp + "/array", mode='r') as A:
3260
- ... A.query(attrs=("a1",), coords=False, order='G')[0:3, 0:10] # doctest: +ELLIPSIS
3261
- OrderedDict( ...'a1'... array([1, 2])... )
3273
+ ... np.testing.assert_equal( A.query(attrs=("a1",), coords=False, order='G')[0:3, 0:10],
3274
+ ... OrderedDict({ 'a1': np. array([1, 2])}) )
3262
3275
3263
3276
"""
3264
3277
if not self .isopen or self .mode not in ('r' , 'd' ):
@@ -3350,6 +3363,7 @@ cdef class SparseArrayImpl(Array):
3350
3363
**Example:**
3351
3364
3352
3365
>>> import tiledb, numpy as np, tempfile
3366
+ >>> from collections import OrderedDict
3353
3367
>>> # Write to multi-attribute 2D array
3354
3368
>>> with tempfile.TemporaryDirectory() as tmp:
3355
3369
... dom = tiledb.Domain(
@@ -3367,8 +3381,10 @@ cdef class SparseArrayImpl(Array):
3367
3381
... "a2": np.array([3, 4])}
3368
3382
... with tiledb.SparseArray(tmp + "/array", mode='r') as A:
3369
3383
... # A[0:3, 0:10], attribute a1, row-major without coordinates
3370
- ... A.subarray((slice(0, 3), slice(0, 10)), attrs=("a1",), coords=False, order='G') # doctest: +ELLIPSIS
3371
- OrderedDict(...'a1'... array([1, 2])...)
3384
+ ... np.testing.assert_equal(
3385
+ ... A.subarray((slice(0, 3), slice(0, 10)), attrs=("a1",), coords=False, order='G'),
3386
+ ... OrderedDict({'a1': np.array([1, 2])})
3387
+ ... )
3372
3388
3373
3389
"""
3374
3390
from .subarray import Subarray
0 commit comments