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
e5358dc
refactor: rename predefined documents (#1208)
samsja Mar 6, 2023
750541f
feat: support other text formats (#1207)
hrik2001 Mar 7, 2023
2f4442a
refactor: refactor query builder (#1213)
JohannesMessner Mar 9, 2023
f428b78
feat(index): automatically convert a dict to Document (#1215)
AnneYang720 Mar 10, 2023
1d34d4d
refactor: da stack full column wise (#1183)
samsja Mar 10, 2023
684ecc8
add equal function
RStar2022 Mar 12, 2023
991c991
Add equality function
RStar2022 Mar 13, 2023
ca678fb
Add equal to array and document
RStar2022 Mar 13, 2023
4ef2070
changes a bit
RStar2022 Mar 16, 2023
9da3d64
add __eq__ function in abstract_comp_backend and add test_array
RStar2022 Mar 17, 2023
25d87c5
feat: ellipsis in tensor shape definition (#1228)
jupyterjazz Mar 14, 2023
17ec781
chore: update contributing guideline (#1240)
samsja Mar 15, 2023
ceb7400
fix equality funtion
RStar2022 Mar 17, 2023
f9d9290
refactor: da stack full column wise (#1183)
samsja Mar 10, 2023
b347151
chore: update contribution guideline (#1247)
samsja Mar 16, 2023
dcabe44
make default search field empty string (#1249)
azayz Mar 16, 2023
e83d740
delete import numpy
RStar2022 Mar 17, 2023
5deebf3
fix key name
RStar2022 Mar 17, 2023
8ae87a6
feat:changes-equality-operation
RStar2022 Mar 19, 2023
f6f2deb
feat:add if
RStar2022 Mar 20, 2023
d75ad29
docs: add explanation about id field (#1242)
JohannesMessner Mar 20, 2023
128f53f
feat: shift to mkdocs (#1244)
samsja Mar 20, 2023
d8e2422
fix:equal func
RStar2022 Mar 21, 2023
e464578
refactor: rename filter to filter_docs to avoid shadowing of filtern …
Mar 20, 2023
55d8ba1
feat: ad user defined mapping for python type to db type (#1252)
Mar 20, 2023
f5a68c2
fix:tensor type func
RStar2022 Mar 21, 2023
baca538
fix: comp_backend code delete
RStar2022 Mar 21, 2023
75c03f1
feat(index): index data with union types (#1220)
JohannesMessner Mar 21, 2023
a010647
fix eq
RStar2022 Mar 24, 2023
c747186
fix: move test to integration test (#1260)
samsja Mar 21, 2023
d3a4e41
fix: disable pycharm da property detection (#1262)
Mar 21, 2023
a9ea305
feat: add minimal logger (#1254)
jupyterjazz Mar 22, 2023
0ba1009
fix: bytes type in `TextDoc` and `VideoDoc` (#1270)
Mar 22, 2023
7436ba1
refactor: doc index structure (#1266)
jupyterjazz Mar 22, 2023
b00741c
refactor(da): remove tensor type from `DocumentArray` init (#1268)
samsja Mar 22, 2023
51214f5
refactor: bytes to bytes_ in predefined documents (#1273)
Mar 22, 2023
97a450f
fix: doc summary for dict and set attributes (#1279)
Mar 23, 2023
e99e4aa
feat: add `get_paths()` instead of v1 `from_files()` (#1267)
Mar 23, 2023
0bd8a60
fix: proto ser and deser for nested tuple/dict/list (#1278)
samsja Mar 23, 2023
8273c47
feat: create documents from dict (#1283)
jupyterjazz Mar 23, 2023
07a5db5
docs: fix up english (#1285)
alexcg1 Mar 23, 2023
6b9d19f
fix: add int, float and others to doc summary (#1287)
Mar 24, 2023
d6969ef
fix: hnswlib doc index (#1277)
JohannesMessner Mar 24, 2023
3f09963
fix
RStar2022 Mar 27, 2023
ebf1d69
fix: tensorflow
RStar2022 Mar 27, 2023
c151332
feat(test): DocumentArray method tests similar to list methods like r…
agaraman0 Mar 27, 2023
63b87cc
fix:doc
RStar2022 Mar 30, 2023
c57a464
feat: implement push/pull interface from JAC, file and s3 (#1182)
Jackmin801 Mar 27, 2023
e0ee245
refactor: rename `Document` to `Doc` (#1293)
samsja Mar 28, 2023
b85c23c
chore(docs): add ci and fix docs ui (#1295)
samsja Mar 28, 2023
b413406
chore: add docstring test (#1298)
samsja Mar 28, 2023
4b1166a
fix: rename DocArrayProto to DocumentArrayProto (#1297)
samsja Mar 28, 2023
12cd7fe
fix: docstring polish typing (#1299)
samsja Mar 28, 2023
de8eac8
fix: remove files (#1305)
samsja Mar 29, 2023
1ac999a
fix: flatten schema of abstract index (#1294)
AnneYang720 Mar 29, 2023
46e8aae
docs: add utils section (#1307)
samsja Mar 29, 2023
2c94e46
docs: fix docstring example of find_batched (#1308)
JohannesMessner Mar 29, 2023
5d05617
docs: fix map docstring (#1311)
samsja Mar 29, 2023
55b6ef2
feat: elasticsearch document index (#1196)
AnneYang720 Mar 29, 2023
f00f1a3
refactor: map_docs_batch to map_docs_batched (#1312)
Mar 29, 2023
7935a15
refactor: map_docs_batch to map_docs_batched (#1312)
Mar 29, 2023
c8f9cb4
feat: torch backend basic operation tests (#1306)
agaraman0 Mar 29, 2023
092e0ab
chore: add instructions to pip installs and group extras (#1281)
Mar 30, 2023
01ff2eb
fix: mark es test as index (#1314)
samsja Mar 30, 2023
b505be0
feat: docarray fastapi simple integration (#1320)
jupyterjazz Mar 31, 2023
ff4f2d3
fix doc
RStar2022 Apr 2, 2023
74ac65a
Merge branch 'feat-rewrite-v2' into Fix_equal_document
RStar2022 Apr 2, 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
10 changes: 10 additions & 0 deletions docarray/array/array/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def construct(
da._data = docs if isinstance(docs, list) else list(docs)
return da


def __eq__(self, other: Any) -> bool:
if self.__len__() != other.__len__():
return False
for doc_self, doc_other in zip(self, other):
if doc_self != doc_other:
return False
return True


def _validate_docs(self, docs: Iterable[T_doc]) -> Iterable[T_doc]:
"""
Validate if an Iterable of Document are compatible with this DocArray
Expand Down
36 changes: 36 additions & 0 deletions docarray/base_doc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,45 @@ def __setattr__(self, field, value) -> None:
dict_ref[key] = val
object.__setattr__(self, '__dict__', dict_ref)


def __eq__(self, other) -> bool:
if self.dict().keys() != other.dict().keys():
return False

for field_name in self.__fields__:
value1 = getattr(self, field_name)
value2 = getattr(other, field_name)

if field_name == 'id':
continue

if isinstance(value1, AbstractTensor) and isinstance(
value2, AbstractTensor
):

comp_be1 = value1.get_comp_backend()
comp_be2 = value2.get_comp_backend()

if comp_be1.shape(value1) != comp_be2.shape(value2):
return False
if (
not (comp_be1.to_numpy(value1) == comp_be2.to_numpy(value2))
.all()
.item()
):
return False
else:
if value1 != value2:
return False
return True

def __ne__(self, other) -> bool:
return not (self == other)

def _docarray_to_json_compatible(self) -> Dict:
"""
Convert itself into a json compatible object
:return: A dictionary of the BaseDoc object
"""
return self.dict()

71 changes: 70 additions & 1 deletion tests/units/array/test_array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Optional, TypeVar, Union

import numpy as np
import pytest
import torch
Expand All @@ -10,6 +9,8 @@

tf_available = is_tf_available()
if tf_available:
import tensorflow as tf

from docarray.typing import TensorFlowTensor


Expand Down Expand Up @@ -80,6 +81,74 @@ class Text(BaseDoc):
assert len(da) == 10


def test_ndarray_equality():
class Text(BaseDoc):
tensor: NdArray

arr1 = Text(tensor=np.zeros(5))
arr2 = Text(tensor=np.zeros(5))
arr3 = Text(tensor=np.ones(5))
arr4 = Text(tensor=np.zeros(4))

assert arr1 == arr2
assert arr1 != arr3
assert arr1 != arr4


def test_tensor_equality():
class Text(BaseDoc):
tensor: TorchTensor

torch1 = Text(tensor=torch.zeros(128))
torch2 = Text(tensor=torch.zeros(128))
torch3 = Text(tensor=torch.zeros(126))
torch4 = Text(tensor=torch.ones(128))

assert torch1 == torch2
assert torch1 != torch3
assert torch1 != torch4


def test_documentarray():
class Text(BaseDoc):
text: str

da1 = DocArray([Text(text='hello')])
da2 = DocArray([Text(text='hello')])

assert da1 == da2
assert da1 == [Text(text='hello') for _ in range(len(da1))]
assert da2 == [Text(text='hello') for _ in range(len(da2))]


@pytest.mark.tensorflow
def test_tensorflowtensor_equality():

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.

Suggested change
def test_tensorflowtensor_equality():
pytest.mark.tensorflow
def test_tensorflowtensor_equality():

class Text(BaseDoc):
tensor: TensorFlowTensor

tensor1 = Text(tensor=tf.constant([1, 2, 3, 4, 5, 6]))
tensor2 = Text(tensor=tf.constant([1, 2, 3, 4, 5, 6]))
tensor3 = Text(tensor=tf.constant([[1.0, 2.0], [3.0, 5.0]]))
tensor4 = Text(tensor=tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]))

assert tensor1 == tensor2
assert tensor1 != tensor3
assert tensor1 != tensor4


def test_text_tensor():
class Text1(BaseDoc):
tensor: NdArray

class Text2(BaseDoc):
tensor: TorchTensor

arr_tensor1 = Text1(tensor=np.zeros(2))
arr_tensor2 = Text2(tensor=torch.zeros(2))

assert arr_tensor1 == arr_tensor2


def test_get_bulk_attributes_function():
class Mmdoc(BaseDoc):
text: str
Expand Down
3 changes: 2 additions & 1 deletion tests/units/document/test_docs_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def test_text_document_operators():
assert doc == doc2

doc3 = TextDoc(id='other-id', text='text', url='http://url.com')
assert doc != doc3
assert doc == doc3


assert 't' in doc
assert 'a' not in doc
Expand Down