diff --git a/docarray/array/mixins/content.py b/docarray/array/mixins/content.py index cce63796c00..13676001a5f 100644 --- a/docarray/array/mixins/content.py +++ b/docarray/array/mixins/content.py @@ -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: + 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) diff --git a/docarray/document/mixins/helper.py b/docarray/document/mixins/helper.py index d1145c49ca9..043275b445f 100644 --- a/docarray/document/mixins/helper.py +++ b/docarray/document/mixins/helper.py @@ -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 @@ -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 diff --git a/docarray/helper.py b/docarray/helper.py index 7539c25ac58..cce4d4765b7 100644 --- a/docarray/helper.py +++ b/docarray/helper.py @@ -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( diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index d5efbebb7ce..e8e5ad2d364 100644 --- a/tests/unit/document/test_converters.py +++ b/tests/unit/document/test_converters.py @@ -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__))