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
9 changes: 7 additions & 2 deletions docarray/array/mixins/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,15 @@ def contents(
):
"""Set the :attr:`.content` of all Documents.

:param value: a list of texts, blobs or :class:`ArrayType`
:param value: a list of texts, blobs or :class:`ArrayType`. If the value is a two-element tuple,
then the second element is used as the :attr:`.content_type`
"""
if self:
content_type = self[0].content_type or self[-1].content_type
if isinstance(value, tuple) and len(value) == 2:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will make the interface complicated, is there a need for this ?

content_type = value[1]
else:
content_type = self[0].content_type or self[-1].content_type

if content_type:
setattr(self, f'{content_type}s', value)

Expand Down
7 changes: 1 addition & 6 deletions docarray/document/mixins/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import urllib.request
from contextlib import nullcontext

from ...helper import __windows__


def _uri_to_blob(uri: str) -> bytes:
"""Convert uri to blob
Expand All @@ -28,10 +26,7 @@ def _get_file_context(file):
if hasattr(file, 'write'):
file_ctx = nullcontext(file)
else:
if __windows__:
file_ctx = open(file, 'wb', newline='')
else:
file_ctx = open(file, 'wb')
file_ctx = open(file, 'wb')

return file_ctx

Expand Down
1 change: 0 additions & 1 deletion docarray/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
ALLOWED_PROTOCOLS = {'pickle', 'protobuf', 'protobuf-array', 'pickle-array'}
ALLOWED_COMPRESSIONS = {'lz4', 'bz2', 'lzma', 'zlib', 'gzip'}

__windows__ = sys.platform == 'win32'

__resources_path__ = os.path.join(
os.path.dirname(
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/document/test_converters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import sys

import numpy as np
import pytest

from docarray import Document
from docarray.document.generators import from_files
from docarray.helper import __windows__

__windows__ = sys.platform == 'win32'

cur_dir = os.path.dirname(os.path.abspath(__file__))

Expand Down