Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7093585

Browse filesBrowse files
committed
fix(array): fix content on zero len da
1 parent 264c8ab commit 7093585
Copy full SHA for 7093585

3 files changed

+21-4Lines changed: 21 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docarray/array/mixins/content.py‎

Copy file name to clipboardExpand all lines: docarray/array/mixins/content.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def blobs(self) -> Optional['ArrayType']:
5858
5959
:return: a :class:`ArrayType` of blobs
6060
"""
61-
if self[0].content_type == 'blob':
61+
if self and self[0].content_type == 'blob':
6262
if self:
6363
return unravel(self, 'blob')
6464

@@ -84,7 +84,7 @@ def texts(self) -> Optional[List[str]]:
8484
8585
:return: a list of texts
8686
"""
87-
if self[0].content_type == 'text':
87+
if self and self[0].content_type == 'text':
8888
if self:
8989
return [d.text for d in self]
9090

@@ -110,7 +110,7 @@ def buffers(self) -> Optional[List[bytes]]:
110110
111111
:return: a list of buffers
112112
"""
113-
if self[0].content_type == 'buffer':
113+
if self and self[0].content_type == 'buffer':
114114
if self:
115115
return [d.buffer for d in self]
116116

Collapse file

‎tests/unit/array/mixins/test_content.py‎

Copy file name to clipboardExpand all lines: tests/unit/array/mixins/test_content.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ def test_content_getter_setter(cls, content_attr):
4848
np.testing.assert_equal(getattr(da, content_attr[0]), content_attr[1])
4949
da.contents = None
5050
assert da.contents is None
51+
52+
@pytest.mark.parametrize('da_len', [0, 1, 2])
53+
def test_content_empty(da_len):
54+
da = DocumentArray.empty(da_len)
55+
assert not da.texts
56+
assert not da.contents
57+
assert not da.blobs
58+
assert not da.buffers
59+
60+
da.texts = ['hello'] * da_len
61+
if da_len == 0:
62+
assert not da.contents
63+
else:
64+
assert da.contents == ['hello'] * da_len
65+
assert da.texts == ['hello'] * da_len
66+
assert not da.blobs
67+
assert not da.buffers
Collapse file

‎tests/unit/array/test_sequence.py‎

Copy file name to clipboardExpand all lines: tests/unit/array/test_sequence.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def test_append_extend(da_cls):
2121
da.append(Document())
2222
assert len(da) == 2
2323
da.extend([Document(), Document()])
24-
assert len(da) == 4
24+
assert len(da) == 4

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.