Skip to content

Commit 155c635

Browse files
committed
fix: del remove attribute (#304)
* fix: del remove attribute * test: add test that covers fix
1 parent e82ea78 commit 155c635

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docarray/array/mixins/delitem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def __delitem__(self, index: 'DocumentArrayIndexType'):
5656
for _d in self[index[0]]:
5757
for _aa in _attrs:
5858
self._set_doc_attr_by_id(_d.id, _aa, None)
59+
_d.pop(_aa)
60+
5961
elif isinstance(index[0], bool):
6062
self._del_docs_by_mask(index)
6163
elif isinstance(index[0], int):

tests/unit/array/mixins/test_del.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from docarray import DocumentArray, Document
44
from docarray.array.weaviate import DocumentArrayWeaviate
5+
import numpy as np
56

67

78
@pytest.fixture()
@@ -81,3 +82,26 @@ def test_del_da_persist(da_cls, config, persist, docs, start_storage):
8182
assert len(da2) == len(docs)
8283
else:
8384
assert len(da2) == 0
85+
86+
87+
def test_del_da_attribute():
88+
89+
da = DocumentArray(
90+
[
91+
Document(embedding=np.array([1, 2, 3]), text='d1'),
92+
Document(embedding=np.array([1, 2, 3]), text='d2'),
93+
]
94+
)
95+
96+
q = DocumentArray(
97+
[
98+
Document(embedding=np.array([4, 5, 6]), text='q1'),
99+
Document(embedding=np.array([2, 3, 4]), text='q1'),
100+
]
101+
)
102+
103+
da.match(q)
104+
del da[...][:, 'embedding']
105+
106+
for d in da:
107+
assert d.embedding is None

0 commit comments

Comments
 (0)