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
11 changes: 9 additions & 2 deletions docarray/array/doc_list/doc_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def append(self, doc: T_doc):
as the `.doc_type` of this `DocList` otherwise it will fail.
:param doc: A Document
"""
super().append(self._validate_one_doc(doc))
return super().append(self._validate_one_doc(doc))

def extend(self, docs: Iterable[T_doc]):
"""
Expand All @@ -180,7 +180,14 @@ def extend(self, docs: Iterable[T_doc]):
fail.
:param docs: Iterable of Documents
"""
super().extend(self._validate_docs(docs))
it: Iterable[T_doc] = list()
if self is docs:
# see https://github.com/docarray/docarray/issues/1489
it = list(docs)
else:
it = self._validate_docs(docs)

return super().extend(it)

def insert(self, i: SupportsIndex, doc: T_doc):
"""
Expand Down
13 changes: 12 additions & 1 deletion tests/units/array/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class Text(BaseDoc):
assert da.id == str(i)


def test_extend_itself():
class Text(BaseDoc):
text: str

da = DocList[Text]([Text(text='hello', id=str(i)) for i in range(10)])

da.extend(da)

assert len(da) == 20


def test_slice(da):
da2 = da[0:5]
assert type(da2) == da.__class__
Expand Down Expand Up @@ -331,7 +342,7 @@ class Doc(BaseDoc):
texts = da_sliced.text
assert len(texts) == 5
for i, text in enumerate(texts):
assert text == f'hello{i*2}'
assert text == f'hello{i * 2}'


def test_del_item(da):
Expand Down