Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
a97b461
chore: group extras and add instructions for pip installs
Mar 23, 2023
c346ef8
fix: throw runtime error with install instructions for hnswlib
Mar 23, 2023
9f43985
feat: add instructions for video imports
Mar 24, 2023
d427c3f
feat: add instructions for audio imports
Mar 24, 2023
8690688
feat: add instructions for 3d imports
Mar 24, 2023
c4b6673
feat: add instructions for image imports
Mar 24, 2023
2a0c350
fix: import only audiosegment from pydub
Mar 24, 2023
3242801
fix: generalize audio and image imports
Mar 24, 2023
391215d
fix: add instructions for web imports
Mar 24, 2023
e4119b3
fix: add instructions for web imports
Mar 27, 2023
3eedfec
fix: add instructions for protobuf imports
Mar 27, 2023
d027213
fix: add instructions for lz4 imports
Mar 27, 2023
e5a5f01
fix: fastapi import
Mar 27, 2023
9ffd548
fix: revert changes in protobuf import
Mar 27, 2023
840b0bc
fix: add instructions for torch, without raising error
Mar 27, 2023
e5da8c0
fix: add instructions for torch, with raising error
Mar 27, 2023
41392bc
fix: add instructions for tensorflow
Mar 27, 2023
581206a
fix: base doc io imports
Mar 27, 2023
59452b8
fix: tf in doc index abstract
Mar 27, 2023
49e6759
fix: tf in doc index abstract
Mar 27, 2023
3979340
fix: clean up imports
Mar 27, 2023
9d14836
fix: tf import in doc index
Mar 27, 2023
8437866
fix: add getattr on module level
Mar 27, 2023
d26dae4
fix: import torch for type checking
Mar 27, 2023
0e868f3
fix: add type checking
Mar 27, 2023
58b6c52
fix: test cross backend
Mar 27, 2023
090382d
fix: add missing return statement
Mar 28, 2023
7a6783b
fix: clean up
Mar 28, 2023
f87e3b4
fix: update error message
Mar 28, 2023
91f8da6
fix: remove base document init
Mar 28, 2023
96087bb
fix: clean up
Mar 28, 2023
be07278
fix: add trimesh easy extra
Mar 28, 2023
d6605e2
fix: pil immage importfix: clean up
Mar 28, 2023
a368483
chore: add lz4 to mypy missing type hint section
Mar 28, 2023
1246a4d
docs: add instructions to doc index tutorial
Mar 28, 2023
34ef472
chore: extra pandas and condense module where missing imports ignore
Mar 28, 2023
b26bd14
fix: update poetry lock
Mar 28, 2023
280a5cd
fix: missed imports
Mar 28, 2023
33f78e9
fix: clean up
Mar 28, 2023
a725c3b
fix: revert last commit
Mar 28, 2023
f24042e
revert "fix: missed imports"
Mar 28, 2023
08e3d46
fix: missed imports
Mar 28, 2023
1fe5a1e
wip
Mar 28, 2023
cf19fa5
fix: rename DocArrayProto to DocumentArrayProto (#1297)
samsja Mar 28, 2023
5f237e7
fix: docstring polish typing (#1299)
samsja Mar 28, 2023
305fff9
fix: fix for doc_string test
Mar 29, 2023
bf055c5
fix: try short version in typing init getattr
Mar 29, 2023
80a2dab
fix: shorter version in getattr
Mar 29, 2023
075ca2d
fix: remove files (#1305)
samsja Mar 29, 2023
2e65d00
fix: flatten schema of abstract index (#1294)
AnneYang720 Mar 29, 2023
fde056d
fix: add type hint for lib
Mar 29, 2023
ec5c4f4
fix: add import error to inits getattrs
Mar 29, 2023
550981d
docs: add utils section (#1307)
samsja Mar 29, 2023
e1cf96b
docs: fix docstring example of find_batched (#1308)
JohannesMessner Mar 29, 2023
3010741
docs: fix map docstring (#1311)
samsja Mar 29, 2023
9da5624
feat: elasticsearch document index (#1196)
AnneYang720 Mar 29, 2023
2570be0
fix: add case for elastic search
Mar 29, 2023
9fef701
refactor: map_docs_batch to map_docs_batched (#1312)
Mar 29, 2023
a0264f0
refactor: map_docs_batch to map_docs_batched (#1312)
Mar 29, 2023
fefbe86
fix: clean up
Mar 29, 2023
2557a61
feat: torch backend basic operation tests (#1306)
agaraman0 Mar 29, 2023
3509d27
fix: ci add --fix-missing to apt-get
Mar 30, 2023
81de695
fix: revert "fix: ci add --fix-missing to apt-get"
Mar 30, 2023
b418462
fix: ci apt-get update
Mar 30, 2023
33ff6ba
Merge remote-tracking branch 'origin/feat-rewrite-v2' into chore-pip-…
Mar 30, 2023
fb01b6b
fix: apply samis suggestions from code review
Mar 30, 2023
a40c44f
fix: apply samis suggestions from code review
Mar 30, 2023
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --all-extras
sudo apt-get update
sudo apt-get install --no-install-recommends ffmpeg

- name: Test
Expand Down Expand Up @@ -157,6 +158,7 @@ jobs:
python -m pip install poetry
rm poetry.lock
poetry install --all-extras
sudo apt-get update
sudo apt-get install --no-install-recommends ffmpeg

- name: Test
Expand Down Expand Up @@ -187,6 +189,7 @@ jobs:
python -m pip install poetry
poetry install --all-extras
poetry run pip install protobuf==3.19.0 # we check that we support 3.19
sudo apt-get update
sudo apt-get install --no-install-recommends ffmpeg

- name: Test
Expand Down Expand Up @@ -214,6 +217,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install poetry
poetry install --all-extras
sudo apt-get update
sudo apt-get install --no-install-recommends ffmpeg

- name: Test
Expand Down Expand Up @@ -242,6 +246,7 @@ jobs:
poetry install --all-extras
poetry run pip install protobuf==3.19.0
poetry run pip install tensorflow==2.11.0
sudo apt-get update
sudo apt-get install --no-install-recommends ffmpeg

- name: Test
Expand Down
6 changes: 5 additions & 1 deletion docarray/array/array/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
_dict_to_access_paths,
)
from docarray.utils._internal.compress import _decompress_bytes, _get_compress_ctx
from docarray.utils._internal.misc import import_library

if TYPE_CHECKING:
import pandas as pd
Expand Down Expand Up @@ -500,7 +501,10 @@ def to_pandas(self) -> 'pd.DataFrame':

:return: pandas.DataFrame
"""
import pandas as pd
if TYPE_CHECKING:
import pandas as pd
else:
pd = import_library('pandas', raise_error=True)

fields = self.document_type._get_access_paths()
df = pd.DataFrame(columns=fields)
Expand Down
9 changes: 5 additions & 4 deletions docarray/array/array/sequence_indexing_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc
from typing import (
TYPE_CHECKING,
Any,
Iterable,
MutableSequence,
Expand All @@ -14,7 +15,7 @@

import numpy as np

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

T_item = TypeVar('T_item')
T = TypeVar('T', bound='IndexingSequenceMixin')
Expand Down Expand Up @@ -85,11 +86,11 @@ def _normalize_index_item(
return item.tolist()

# torch index types
torch_available = is_torch_available()
if torch_available:
if TYPE_CHECKING:
import torch
else:
raise ValueError(f'Invalid index type {type(item)}')
torch = import_library('torch', raise_error=True)

allowed_torch_dtypes = [
torch.bool,
torch.int64,
Expand Down
22 changes: 20 additions & 2 deletions docarray/base_doc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
from docarray.base_doc.any_doc import AnyDoc
from docarray.base_doc.base_node import BaseNode
from docarray.base_doc.doc import BaseDoc
from docarray.base_doc.doc_response import DocResponse
from docarray.utils._internal.misc import (
_get_path_from_docarray_root_level,
import_library,
)

__all__ = ['AnyDoc', 'BaseDoc', 'BaseNode', 'DocResponse']
__all__ = ['AnyDoc', 'BaseDoc', 'BaseNode']


def __getattr__(name: str):
if name == 'DocResponse':
import_library('fastapi', raise_error=True)
from docarray.base_doc.doc_response import DocResponse

if name not in __all__:
__all__.append(name)

return DocResponse
else:
raise ImportError(
f'cannot import name \'{name}\' from \'{_get_path_from_docarray_root_level(__file__)}\''
)
16 changes: 7 additions & 9 deletions docarray/base_doc/doc_response.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import Any
from typing import TYPE_CHECKING, Any

try:
from fastapi.responses import JSONResponse, Response
except ImportError:
from docarray.utils._internal.misc import import_library

class NoImportResponse:
def __init__(self, *args, **kwargs):
ImportError('fastapi is not installed')

Response = JSONResponse = NoImportResponse # type: ignore
if TYPE_CHECKING:
from fastapi.responses import JSONResponse
else:
fastapi = import_library('fastapi', raise_error=True)
JSONResponse = fastapi.responses.JSONResponse


class DocResponse(JSONResponse):
Expand Down
27 changes: 13 additions & 14 deletions docarray/base_doc/mixins/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
from docarray.typing import NdArray
from docarray.typing.proto_register import _PROTO_TYPE_NAME_TO_CLASS
from docarray.utils._internal.compress import _compress_bytes, _decompress_bytes
from docarray.utils._internal.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import import_library

tf_available = is_tf_available()
if tf_available:
if TYPE_CHECKING:
import tensorflow as tf # type: ignore

from docarray.typing import TensorFlowTensor

torch_available = is_torch_available()
if torch_available:
import torch

from docarray.typing import TorchTensor

if TYPE_CHECKING:
from pydantic.fields import ModelField

from docarray.proto import DocumentProto, NodeProto
from docarray.typing import TensorFlowTensor, TorchTensor
else:
tf = import_library('tensorflow', raise_error=False)
if tf is not None:
from docarray.typing import TensorFlowTensor

torch = import_library('torch', raise_error=False)
if torch is not None:
from docarray.typing import TorchTensor


T = TypeVar('T', bound='IOMixin')
Expand Down Expand Up @@ -68,12 +67,12 @@ def _type_to_protobuf(value: Any) -> 'NodeProto':
return nested_item

base_node_wrap: BaseNode
if torch_available:
if torch is not None:
if isinstance(value, torch.Tensor):
base_node_wrap = TorchTensor._docarray_from_native(value)
return base_node_wrap._to_node_protobuf()

if tf_available:
if tf is not None:
if isinstance(value, tf.Tensor):
base_node_wrap = TensorFlowTensor._docarray_from_native(value)
return base_node_wrap._to_node_protobuf()
Expand Down
12 changes: 9 additions & 3 deletions docarray/computation/tensorflow_backend.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import typing
from typing import Callable, List, Optional, Tuple
from typing import TYPE_CHECKING, Callable, List, Optional, Tuple

import numpy as np
import tensorflow as tf # type: ignore
import tensorflow._api.v2.experimental.numpy as tnp # type: ignore

from docarray.computation import AbstractComputationalBackend
from docarray.computation.abstract_numpy_based_backend import AbstractNumpyBasedBackend
from docarray.typing import TensorFlowTensor
from docarray.utils._internal.misc import import_library

if TYPE_CHECKING:
import tensorflow as tf # type: ignore
import tensorflow._api.v2.experimental.numpy as tnp # type: ignore
else:
tf = import_library('tensorflow', raise_error=True)
tnp = tf._api.v2.experimental.numpy


def _unsqueeze_if_single_axis(*matrices: tf.Tensor) -> List[tf.Tensor]:
Expand Down
9 changes: 7 additions & 2 deletions docarray/computation/torch_backend.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from typing import Any, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Union

import numpy as np
import torch

from docarray.computation.abstract_comp_backend import AbstractComputationalBackend
from docarray.utils._internal.misc import import_library

if TYPE_CHECKING:
import torch
else:
torch = import_library('torch', raise_error=True)


def _unsqueeze_if_single_axis(*matrices: torch.Tensor) -> List[torch.Tensor]:
Expand Down
19 changes: 9 additions & 10 deletions docarray/documents/audio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar, Union

import numpy as np

Expand All @@ -7,15 +7,14 @@
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._internal.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import import_library

torch_available = is_torch_available()
if torch_available:
import torch

tf_available = is_tf_available()
if tf_available:
if TYPE_CHECKING:
import tensorflow as tf # type: ignore
import torch
else:
torch = import_library('torch', raise_error=False)
tf = import_library('tensorflow', raise_error=False)


T = TypeVar('T', bound='AudioDoc')
Expand Down Expand Up @@ -110,9 +109,9 @@ def validate(
if isinstance(value, str):
value = cls(url=value)
elif isinstance(value, (AbstractTensor, np.ndarray)) or (
torch_available
torch is not None
and isinstance(value, torch.Tensor)
or (tf_available and isinstance(value, tf.Tensor))
or (tf is not None and isinstance(value, tf.Tensor))
):
value = cls(tensor=value)

Expand Down
21 changes: 10 additions & 11 deletions docarray/documents/image.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from typing import Any, Optional, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar, Union

import numpy as np

from docarray.base_doc import BaseDoc
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._internal.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import import_library

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

torch_available = is_torch_available()
if torch_available:
if TYPE_CHECKING:
import tensorflow as tf # type: ignore
import torch
else:
tf = import_library('tensorflow', raise_error=False)
torch = import_library('torch', raise_error=False)

tf_available = is_tf_available()
if tf_available:
import tensorflow as tf # type: ignore
T = TypeVar('T', bound='ImageDoc')


class ImageDoc(BaseDoc):
Expand Down Expand Up @@ -99,8 +98,8 @@ def validate(
value = cls(url=value)
elif (
isinstance(value, (AbstractTensor, np.ndarray))
or (torch_available and isinstance(value, torch.Tensor))
or (tf_available and isinstance(value, tf.Tensor))
or (torch is not None and isinstance(value, torch.Tensor))
or (tf is not None and isinstance(value, tf.Tensor))
):
value = cls(tensor=value)
elif isinstance(value, bytes):
Expand Down
10 changes: 7 additions & 3 deletions docarray/documents/mesh/vertices_and_faces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Type, TypeVar, Union

from docarray.base_doc import BaseDoc
from docarray.typing.tensor.tensor import AnyTensor
from docarray.utils._internal.misc import import_library

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

Expand All @@ -28,9 +29,12 @@ def validate(
def display(self) -> None:
"""
Plot mesh consisting of vertices and faces.
To use this you need to install trimesh[easy]: `pip install 'trimesh[easy]'`.
"""
import trimesh
if TYPE_CHECKING:
import trimesh
else:
trimesh = import_library('trimesh', raise_error=True)

from IPython.display import display

if self.vertices is None or self.faces is None:
Expand Down
18 changes: 9 additions & 9 deletions docarray/documents/point_cloud/point_cloud_3d.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from typing import Any, Optional, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar, Union

import numpy as np

from docarray.base_doc import BaseDoc
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._internal.misc import is_tf_available, is_torch_available
from docarray.utils._internal.misc import import_library

torch_available = is_torch_available()
if torch_available:
if TYPE_CHECKING:
import tensorflow as tf # type: ignore
import torch
else:
tf = import_library('tensorflow', raise_error=False)
torch = import_library('torch', raise_error=False)

tf_available = is_tf_available()
if tf_available:
import tensorflow as tf # type: ignore

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

Expand Down Expand Up @@ -124,9 +124,9 @@ def validate(
if isinstance(value, str):
value = cls(url=value)
elif isinstance(value, (AbstractTensor, np.ndarray)) or (
torch_available
torch is not None
and isinstance(value, torch.Tensor)
or (tf_available and isinstance(value, tf.Tensor))
or (tf is not None and isinstance(value, tf.Tensor))
):
value = cls(tensors=PointsAndColors(points=value))

Expand Down
Loading