Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61db273
feat: indexing by iterable of ints
JohannesMessner Feb 2, 2023
dda16e8
fix: accept all iterables as index
JohannesMessner Feb 2, 2023
a193e45
feat: index by boolean mask
JohannesMessner Feb 2, 2023
e0546d3
feat: allow indexing with torch or numpy
JohannesMessner Feb 2, 2023
3c61c91
feat: add setitem
JohannesMessner Feb 3, 2023
023fc07
fix: set by mask
JohannesMessner Feb 3, 2023
815efe3
test: add tests
JohannesMessner Feb 3, 2023
bc1c54b
test: fix some tests
JohannesMessner Feb 3, 2023
53282ab
fix: some mypy issues
JohannesMessner Feb 3, 2023
67718a4
fix: remove uneeded optimization
JohannesMessner Feb 6, 2023
87a0f8a
fix: index by numpy int type
JohannesMessner Feb 6, 2023
2103d6a
refactor: make torch available check a util function
JohannesMessner Feb 6, 2023
738b93a
Merge branch 'feat-rewrite-v2' into feat-advanced-indexing
JohannesMessner Feb 6, 2023
4ca255d
fix: np indexing
JohannesMessner Feb 6, 2023
0241c03
Merge remote-tracking branch 'origin/feat-advanced-indexing' into fea…
JohannesMessner Feb 6, 2023
5478b0a
fix: mypy stuff
JohannesMessner Feb 6, 2023
eddf528
docs: add docstring
JohannesMessner Feb 6, 2023
0693d35
docs: fix docstring example
JohannesMessner Feb 6, 2023
50984e2
refactor: split columns dict
JohannesMessner Feb 6, 2023
2f2f4f2
docs: tweak docstring
JohannesMessner Feb 7, 2023
acabda4
Merge branch 'feat-rewrite-v2' into feat-advanced-indexing
JohannesMessner Feb 7, 2023
27f3167
test: add test for none indexing
JohannesMessner Feb 7, 2023
1a058dd
fix: adapt proto to changes
JohannesMessner Feb 7, 2023
eb87fc6
refactor: apply black
JohannesMessner Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add docstring
Signed-off-by: Johannes Messner <[email protected]>
  • Loading branch information
JohannesMessner committed Feb 6, 2023
commit eddf528d0f35478f27ee47bc33a5a42e0934c888
25 changes: 23 additions & 2 deletions docarray/array/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class DocumentArray(AnyDocumentArray):
.. code-block:: python
from docarray import BaseDocument, DocumentArray
from docarray.typing import NdArray, ImageUrl
from typing import Optional


class Image(BaseDocument):
Expand All @@ -96,8 +97,28 @@ class Image(BaseDocument):


If your DocumentArray is homogeneous (i.e. follows the same schema), you can access
fields at the DocumentArray level (for example `da.tensor`). You can also set
fields, with `da.tensor = np.random.random([10, 100])`
fields at the DocumentArray level (for example `da.tensor` or `da.url`).
You can also set fields, with `da.tensor = np.random.random([10, 100])`:

.. code-block:: python
print(da.url)
# [ImageUrl('http://url.com/foo.png', host_type='domain'), ...]
import numpy as np

da.tensor = np.random.random([10, 100])
print(da.tensor)
# [NdArray([0.11299577, 0.47206767, 0.481723 , 0.34754724, 0.15016037,
# 0.88861321, 0.88317666, 0.93845579, 0.60486676, ... ]), ...]

You can index into a DocumentArray like a numpy array or torch tensor:

.. code-block:: python
da[0] # index by position
da[0:5:2] # index by slice
da[[0, 2, 3]] # index by list of indices
da[da.tensor > 0.5] # index by boolean mask


"""

document_type: Type[BaseDocument] = AnyDocument
Expand Down