Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docarray/array/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __getitem__(
def __getitem__(
self, index: 'DocumentArrayIndexType'
) -> Union['Document', 'DocumentArray']:
if isinstance(index, (int, np.generic)):
if isinstance(index, (int, np.generic)) and not isinstance(index, bool):
return self._data[int(index)]
elif isinstance(index, str):
if index.startswith('@'):
Expand Down
2 changes: 2 additions & 0 deletions docs/fundamentals/documentarray/access-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ print(da)
<DocumentArray (length=50) at 4513619088>
```

Note that if the length of the boolean mask is smaller than the length of a DocumentArray, then the remaining part is padded to `False`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add 'The length of the boolean mask should be at least 2'.


(path-string)=
## Index by nested structure

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/array/test_advance_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ def test_advance_selector_mixed():

assert len(da[:, ('id', 'embedding', 'matches')]) == 3
assert len(da[:, ('id', 'embedding', 'matches')][0]) == 10


def test_single_boolean_and_padding():
from docarray import DocumentArray

da = DocumentArray.empty(3)

with pytest.raises(IndexError):
da[True]

assert len(da[True, False]) == 1
assert len(da[False, False]) == 0