Skip to content

Commit 586c602

Browse files
committed
Fix OrderedDict formatting in docs
1 parent f21ae54 commit 586c602

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

tiledb/libtiledb.pyx

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,8 @@ cdef class Array(object):
15111511
15121512
** Example **
15131513
1514-
>>> import tiledb, numpy as np
1515-
>>>
1514+
>>> import tiledb, numpy as np, tempfile
1515+
>>> from collections import OrderedDict
15161516
>>> dim1 = tiledb.Dim("d1", domain=(1, 4))
15171517
>>> dim2 = tiledb.Dim("d2", domain=(1, 3))
15181518
>>> dom = tiledb.Domain(dim1, dim2)
@@ -1537,21 +1537,30 @@ cdef class Array(object):
15371537
... A[:] = {"a1": a1_data, "l1": l1_data, "l2": l2_data, "l3": l3_data}
15381538
...
15391539
... 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+
... )
15551564
15561565
:param labels: List of labels to use when querying. Can only use at most one
15571566
label per dimension.
@@ -1560,6 +1569,7 @@ cdef class Array(object):
15601569
query the array on the corresponding dimension.
15611570
:returns: dict of {'label/attribute': result}.
15621571
:raises: :py:exc:`tiledb.TileDBError`
1572+
15631573
"""
15641574
# Delayed to avoid circular import
15651575
from .multirange_indexing import LabelIndexer
@@ -2144,8 +2154,7 @@ cdef class DenseArrayImpl(Array):
21442154
def query(self, attrs=None, attr_cond=None, cond=None, dims=None,
21452155
coords=False, order='C', use_arrow=None, return_arrow=False,
21462156
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
21492158
for an item or region of the array across one or more attributes.
21502159
21512160
Optionally subselect over attributes, return dense result coordinate values,
@@ -2188,8 +2197,8 @@ cdef class DenseArrayImpl(Array):
21882197
... A[0:10] = {"a1": np.zeros((10)), "a2": np.ones((10))}
21892198
... with tiledb.DenseArray(tmp + "/array", mode='r') as A:
21902199
... # 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)})
21932202
21942203
"""
21952204
if not self.isopen or self.mode != 'r':
@@ -2243,8 +2252,8 @@ cdef class DenseArrayImpl(Array):
22432252
... A[0:10] = {"a1": np.zeros((10)), "a2": np.ones((10))}
22442253
... with tiledb.DenseArray(tmp + "/array", mode='r') as A:
22452254
... # 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)}))
22482257
22492258
"""
22502259
from .subarray import Subarray
@@ -3164,6 +3173,7 @@ cdef class SparseArrayImpl(Array):
31643173
**Example:**
31653174
31663175
>>> import tiledb, numpy as np, tempfile
3176+
>>> from collections import OrderedDict
31673177
>>> # Write to multi-attribute 2D array
31683178
>>> with tempfile.TemporaryDirectory() as tmp:
31693179
... dom = tiledb.Domain(
@@ -3181,10 +3191,12 @@ cdef class SparseArrayImpl(Array):
31813191
... "a2": np.array([3, 4])}
31823192
... with tiledb.SparseArray(tmp + "/array", mode='r') as A:
31833193
... # 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)}))
31853197
... # 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)
31883200
31893201
With a floating-point array domain, index bounds are inclusive, e.g.:
31903202
@@ -3241,6 +3253,7 @@ cdef class SparseArrayImpl(Array):
32413253
**Example:**
32423254
32433255
>>> import tiledb, numpy as np, tempfile
3256+
>>> from collections import OrderedDict
32443257
>>> # Write to multi-attribute 2D array
32453258
>>> with tempfile.TemporaryDirectory() as tmp:
32463259
... dom = tiledb.Domain(
@@ -3257,8 +3270,8 @@ cdef class SparseArrayImpl(Array):
32573270
... A[I, J] = {"a1": np.array([1, 2]),
32583271
... "a2": np.array([3, 4])}
32593272
... 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])}))
32623275
32633276
"""
32643277
if not self.isopen or self.mode not in ('r', 'd'):
@@ -3350,6 +3363,7 @@ cdef class SparseArrayImpl(Array):
33503363
**Example:**
33513364
33523365
>>> import tiledb, numpy as np, tempfile
3366+
>>> from collections import OrderedDict
33533367
>>> # Write to multi-attribute 2D array
33543368
>>> with tempfile.TemporaryDirectory() as tmp:
33553369
... dom = tiledb.Domain(
@@ -3367,8 +3381,10 @@ cdef class SparseArrayImpl(Array):
33673381
... "a2": np.array([3, 4])}
33683382
... with tiledb.SparseArray(tmp + "/array", mode='r') as A:
33693383
... # 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+
... )
33723388
33733389
"""
33743390
from .subarray import Subarray

0 commit comments

Comments
 (0)