Skip to content

Commit

Permalink
fix(array): remove the support of singleton boolean index (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Jan 11, 2022
1 parent beeb322 commit 3a906db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docarray/array/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __setitem__(
index: 'DocumentArrayIndexType',
value: Union['Document', Sequence['Document']],
):
if isinstance(index, (int, np.generic)):
if isinstance(index, (int, np.generic)) and not isinstance(index, bool):
index = int(index)
self._data[index] = value
self._id2offset[value.id] = index
Expand Down Expand Up @@ -289,7 +289,7 @@ def __setitem__(
raise IndexError(f'Unsupported index type {typename(index)}: {index}')

def __delitem__(self, index: 'DocumentArrayIndexType'):
if isinstance(index, (int, np.generic)):
if isinstance(index, (int, np.generic)) and not isinstance(index, bool):
index = int(index)
self._id2offset.pop(self._data[index].id)
del self._data[index]
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/array/test_advance_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,11 @@ def test_single_boolean_and_padding():
with pytest.raises(IndexError):
da[True]

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

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

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

0 comments on commit 3a906db

Please sign in to comment.