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: 2 additions & 0 deletions docarray/array/mixins/delitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __delitem__(self, index: 'DocumentArrayIndexType'):
for _d in self[index[0]]:
for _aa in _attrs:
self._set_doc_attr_by_id(_d.id, _aa, None)
_d.pop(_aa)

elif isinstance(index[0], bool):
self._del_docs_by_mask(index)
elif isinstance(index[0], int):
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/array/mixins/test_del.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from docarray import DocumentArray, Document
from docarray.array.weaviate import DocumentArrayWeaviate
import numpy as np


@pytest.fixture()
Expand Down Expand Up @@ -81,3 +82,26 @@ def test_del_da_persist(da_cls, config, persist, docs, start_storage):
assert len(da2) == len(docs)
else:
assert len(da2) == 0


def test_del_da_attribute():

da = DocumentArray(
[
Document(embedding=np.array([1, 2, 3]), text='d1'),
Document(embedding=np.array([1, 2, 3]), text='d2'),
]
)

q = DocumentArray(
[
Document(embedding=np.array([4, 5, 6]), text='q1'),
Document(embedding=np.array([2, 3, 4]), text='q1'),
]
)

da.match(q)
del da[...][:, 'embedding']

for d in da:
assert d.embedding is None