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
2 changes: 1 addition & 1 deletion docarray/array/abstract_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from docarray.base_doc import BaseDoc
from docarray.display.document_array_summary import DocArraySummary
from docarray.typing.abstract_type import AbstractType
from docarray.utils._typing import change_cls_name
from docarray.utils._internal._typing import change_cls_name

if TYPE_CHECKING:
from docarray.proto import DocArrayProto, NodeProto
Expand Down
8 changes: 4 additions & 4 deletions docarray/array/array/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
_all_access_paths_valid,
_dict_to_access_paths,
)
from docarray.utils.compress import _decompress_bytes, _get_compress_ctx
from docarray.utils._internal.compress import _decompress_bytes, _get_compress_ctx

if TYPE_CHECKING:
import pandas as pd
Expand Down Expand Up @@ -201,7 +201,7 @@ def to_binary_stream(
from rich import filesize

if show_progress:
from docarray.utils.progress_bar import _get_progressbar
from docarray.utils._internal.progress_bar import _get_progressbar

pbar, t = _get_progressbar(
'Serializing', disable=not show_progress, total=len(self)
Expand Down Expand Up @@ -564,7 +564,7 @@ def _load_binary_all(
else:
from rich import filesize

from docarray.utils.progress_bar import _get_progressbar
from docarray.utils._internal.progress_bar import _get_progressbar

# 1 byte (uint8)
# 8 bytes (uint64)
Expand Down Expand Up @@ -629,7 +629,7 @@ def _load_binary_stream(
num_docs = int.from_bytes(version_numdocs_lendoc0[1:9], 'big', signed=False)

if show_progress:
from docarray.utils.progress_bar import _get_progressbar
from docarray.utils._internal.progress_bar import _get_progressbar

pbar, t = _get_progressbar(
'Deserializing', disable=not show_progress, total=num_docs
Expand Down
2 changes: 1 addition & 1 deletion docarray/array/array/sequence_indexing_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import numpy as np

from docarray.utils.misc import is_torch_available
from docarray.utils._internal.misc import is_torch_available

T_item = TypeVar('T_item')
T = TypeVar('T', bound='IndexingSequenceMixin')
Expand Down
4 changes: 2 additions & 2 deletions docarray/array/stacked/array_stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from docarray.base_doc.mixins.io import _type_to_protobuf
from docarray.typing import NdArray
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.utils._typing import is_tensor_union
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal._typing import is_tensor_union
from docarray.utils._internal.misc import is_tf_available, is_torch_available

if TYPE_CHECKING:
from pydantic.fields import ModelField
Expand Down
4 changes: 2 additions & 2 deletions docarray/base_doc/mixins/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from docarray.base_doc.base_node import BaseNode
from docarray.typing import NdArray
from docarray.typing.proto_register import _PROTO_TYPE_NAME_TO_CLASS
from docarray.utils.compress import _compress_bytes, _decompress_bytes
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.compress import _compress_bytes, _decompress_bytes
from docarray.utils._internal.misc import is_tf_available, is_torch_available

tf_available = is_tf_available()
if tf_available:
Expand Down
2 changes: 1 addition & 1 deletion docarray/data/torch_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from docarray import BaseDoc, DocArray, DocArrayStacked
from docarray.typing import TorchTensor
from docarray.utils._typing import change_cls_name
from docarray.utils._internal._typing import change_cls_name

T_doc = TypeVar('T_doc', bound=BaseDoc)

Expand Down
2 changes: 1 addition & 1 deletion docarray/documents/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from docarray.typing.bytes.audio_bytes import AudioBytes
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.typing.tensor.audio.audio_tensor import AudioTensor
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

torch_available = is_torch_available()
if torch_available:
Expand Down
2 changes: 1 addition & 1 deletion docarray/documents/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from docarray.typing import AnyEmbedding, ImageBytes, ImageUrl
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.typing.tensor.image.image_tensor import ImageTensor
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

T = TypeVar('T', bound='ImageDoc')

Expand Down
2 changes: 1 addition & 1 deletion docarray/documents/point_cloud/point_cloud_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from docarray.documents.point_cloud.points_and_colors import PointsAndColors
from docarray.typing import AnyEmbedding, PointCloud3DUrl
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

torch_available = is_torch_available()
if torch_available:
Expand Down
2 changes: 1 addition & 1 deletion docarray/documents/point_cloud/points_and_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from docarray.base_doc import BaseDoc
from docarray.typing import AnyTensor
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

torch_available = is_torch_available()
if torch_available:
Expand Down
2 changes: 1 addition & 1 deletion docarray/documents/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from docarray.typing.tensor.abstract_tensor import AbstractTensor
from docarray.typing.tensor.video.video_tensor import VideoTensor
from docarray.typing.url.video_url import VideoUrl
from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

torch_available = is_torch_available()
if torch_available:
Expand Down
4 changes: 2 additions & 2 deletions docarray/index/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from docarray import BaseDoc, DocArray
from docarray.array.abstract_array import AnyDocArray
from docarray.typing import AnyTensor
from docarray.utils._typing import unwrap_optional_type
from docarray.utils._internal._typing import unwrap_optional_type
from docarray.utils._internal.misc import is_tf_available, torch_imported
from docarray.utils.find import FindResult, _FindResult
from docarray.utils.misc import is_tf_available, torch_imported

if TYPE_CHECKING:
from pydantic.fields import ModelField
Expand Down
2 changes: 1 addition & 1 deletion docarray/index/backends/hnswlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
_raise_not_supported,
)
from docarray.proto import DocumentProto
from docarray.utils._internal.misc import is_np_int, is_tf_available, is_torch_available
from docarray.utils.filter import filter_docs
from docarray.utils.find import _FindResult
from docarray.utils.misc import is_np_int, is_tf_available, is_torch_available

TSchema = TypeVar('TSchema', bound=BaseDoc)
T = TypeVar('T', bound='HnswDocumentIndex')
Expand Down
4 changes: 2 additions & 2 deletions docarray/store/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from docarray.store.abstract_doc_store import AbstractDocStore
from docarray.store.exceptions import ConcurrentPushException
from docarray.store.helpers import _from_binary_stream, _to_binary_stream
from docarray.utils.cache import get_cache_path
from docarray.utils._internal.cache import _get_cache_path

if TYPE_CHECKING:
from docarray import BaseDoc, DocArray
Expand All @@ -23,7 +23,7 @@ def _abs_filepath(name: str) -> Path:
If it is a path, it is resolved to an absolute path.
"""
if not (name.startswith('/') or name.startswith('~') or name.startswith('.')):
name = str(get_cache_path() / name)
name = str(_get_cache_path() / name)
if name.startswith('~'):
name = str(Path.home() / name[2:])
return Path(name).resolve()
Expand Down
2 changes: 1 addition & 1 deletion docarray/store/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rich import filesize
from typing_extensions import TYPE_CHECKING, Protocol

from docarray.utils.progress_bar import _get_progressbar
from docarray.utils._internal.progress_bar import _get_progressbar

if TYPE_CHECKING:
from pathlib import Path
Expand Down
6 changes: 3 additions & 3 deletions docarray/store/jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
get_version_info,
raise_req_error,
)
from docarray.utils.cache import get_cache_path
from docarray.utils._internal.cache import _get_cache_path

if TYPE_CHECKING: # pragma: no cover
import io
Expand Down Expand Up @@ -331,7 +331,7 @@ def pull_stream(
_BufferedCachingRequestReader, io.BufferedReader
] = _BufferedCachingRequestReader(r, tmp_cache_file)

cache_file = get_cache_path() / f'{save_name}.da'
cache_file = _get_cache_path() / f'{save_name}.da'
if local_cache and cache_file.exists():
_cache_len = cache_file.stat().st_size
if _cache_len == int(r.headers['Content-length']):
Expand All @@ -354,7 +354,7 @@ def pull_stream(

if local_cache:
if isinstance(_source, _BufferedCachingRequestReader):
Path(get_cache_path()).mkdir(parents=True, exist_ok=True)
Path(_get_cache_path()).mkdir(parents=True, exist_ok=True)
tmp_cache_file.rename(cache_file)
else:
_source.close()
4 changes: 2 additions & 2 deletions docarray/store/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from docarray.store.abstract_doc_store import AbstractDocStore
from docarray.store.helpers import _from_binary_stream, _to_binary_stream
from docarray.utils.cache import get_cache_path
from docarray.utils._internal.cache import _get_cache_path

if TYPE_CHECKING: # pragma: no cover
from docarray import BaseDoc, DocArray
Expand Down Expand Up @@ -212,7 +212,7 @@ def pull_stream(
bucket, name = name.split('/', 1)

save_name = name.replace('/', '_')
cache_path = get_cache_path() / f'{save_name}.da'
cache_path = _get_cache_path() / f'{save_name}.da'

source = _BufferedCachingReader(
open(f"s3://{bucket}/{name}.da", 'rb', compression='.gz'),
Expand Down
10 changes: 6 additions & 4 deletions docarray/typing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from docarray.typing.bytes import ImageBytes
from docarray.typing.bytes import AudioBytes, ImageBytes, VideoBytes
from docarray.typing.id import ID
from docarray.typing.tensor import ImageNdArray, ImageTensor
from docarray.typing.tensor.audio import AudioNdArray
Expand Down Expand Up @@ -31,14 +31,16 @@
'AnyUrl',
'ID',
'AnyTensor',
'TensorFlowTensor',
'NdArrayEmbedding',
'ImageBytes',
'ImageTensor',
'ImageNdArray',
'ImageBytes',
'VideoBytes',
'AudioBytes',
]

from docarray.utils.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import is_tf_available, is_torch_available

torch_available = is_torch_available()
if torch_available:
Expand All @@ -59,7 +61,7 @@

tf_available = is_tf_available()
if tf_available:
from docarray.typing.tensor import TensorFlowTensor
from docarray.typing.tensor import TensorFlowTensor # noqa: F401
from docarray.typing.tensor.audio import AudioTensorFlowTensor # noqa: F401
from docarray.typing.tensor.embedding import TensorFlowEmbedding # noqa: F401
from docarray.typing.tensor.image import ImageTensorFlowTensor # noqa: F401
Expand Down
4 changes: 3 additions & 1 deletion docarray/typing/bytes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from docarray.typing.bytes.audio_bytes import AudioBytes
from docarray.typing.bytes.image_bytes import ImageBytes
from docarray.typing.bytes.video_bytes import VideoBytes

__all__ = ['ImageBytes']
__all__ = ['ImageBytes', 'VideoBytes', 'AudioBytes']
35 changes: 19 additions & 16 deletions docarray/typing/bytes/audio_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,35 @@ def load(self) -> Tuple[np.ndarray, int]:
"""
Load the Audio from the bytes into a numpy.ndarray Audio tensor

EXAMPLE USAGE
---

.. code-block:: python
```python
from typing import Optional
from docarray import BaseDoc
from docarray.typing import AudioUrl, NdArray, AudioBytes

from docarray import BaseDoc
import numpy as np
import numpy as np

from docarray.typing import AudioUrl

class MyAudio(BaseDoc):
url: AudioUrl
tensor: Optional[NdArray]
bytes: Optional[AudioBytes]
frame_rate: Optional[float]

class MyAudio(Document):
url: AudioUrl
tensor: Optional[NdArray]
bytes: Optional[bytes]

doc = MyAudio(url='https://www.kozco.com/tech/piano2.wav')
doc.bytes = doc.url.load_bytes()
doc.tensor, doc.frame_rate = doc.bytes.load()

doc = MyAudio(url="toydata/hello.wav")
doc.bytes = doc.url.load_bytes()
doc.tensor, doc.frame_rate = doc.bytes.load()
# Note this is equivalent to do

# Note this is equivalent to do
doc.tensor, doc.frame_rate = doc.url.load()

doc.tensor, doc.frame_rate = doc.url.load()

assert isinstance(doc.audio_tensor, np.ndarray)
assert isinstance(doc.tensor, np.ndarray)
```

---
:return: np.ndarray representing the Audio as RGB values
"""

Expand Down
39 changes: 20 additions & 19 deletions docarray/typing/bytes/image_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,35 @@ def load(
"""
Load the image from the bytes into a numpy.ndarray image tensor

EXAMPLE USAGE
---

.. code-block:: python
```python
from docarray import BaseDoc
from docarray.typing import ImageUrl
import numpy as np

from docarray import BaseDoc
from docarray.typing import ImageUrl
import numpy as np

class MyDoc(BaseDoc):
img_url: ImageUrl

class MyDoc(BaseDoc):
img_url: ImageUrl

doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)

doc = MyDoc(
img_url="https://upload.wikimedia.org/wikipedia/commons/8/80/"
"Dag_Sebastian_Ahlander_at_G%C3%B6teborg_Book_Fair_2012b.jpg"
)
img_tensor = doc.img_url.load()
assert isinstance(img_tensor, np.ndarray)

img_tensor = doc.img_url.load()
assert isinstance(img_tensor, np.ndarray)
img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)

img_tensor = doc.img_url.load(height=224, width=224)
assert img_tensor.shape == (224, 224, 3)

layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
layout = ('C', 'W', 'H')
img_tensor = doc.img_url.load(height=100, width=200, axis_layout=layout)
assert img_tensor.shape == (3, 200, 100)
```

---

:param width: width of the image tensor.
:param height: height of the image tensor.
Expand Down
Loading