Skip to content

Commit 3a906db

Browse files
authored
fix(array): remove the support of singleton boolean index (#31)
1 parent beeb322 commit 3a906db

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docarray/array/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __setitem__(
205205
index: 'DocumentArrayIndexType',
206206
value: Union['Document', Sequence['Document']],
207207
):
208-
if isinstance(index, (int, np.generic)):
208+
if isinstance(index, (int, np.generic)) and not isinstance(index, bool):
209209
index = int(index)
210210
self._data[index] = value
211211
self._id2offset[value.id] = index
@@ -289,7 +289,7 @@ def __setitem__(
289289
raise IndexError(f'Unsupported index type {typename(index)}: {index}')
290290

291291
def __delitem__(self, index: 'DocumentArrayIndexType'):
292-
if isinstance(index, (int, np.generic)):
292+
if isinstance(index, (int, np.generic)) and not isinstance(index, bool):
293293
index = int(index)
294294
self._id2offset.pop(self._data[index].id)
295295
del self._data[index]

tests/unit/array/test_advance_indexing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,11 @@ def test_single_boolean_and_padding():
229229
with pytest.raises(IndexError):
230230
da[True]
231231

232+
with pytest.raises(IndexError):
233+
da[True] = Document()
234+
235+
with pytest.raises(IndexError):
236+
del da[True]
237+
232238
assert len(da[True, False]) == 1
233239
assert len(da[False, False]) == 0

0 commit comments

Comments
 (0)