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
4 changes: 3 additions & 1 deletion docarray/array/queryset/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"""
from typing import TYPE_CHECKING

from docarray.document.data import _is_not_empty

if TYPE_CHECKING:
from docarray import Document
import re
Expand Down Expand Up @@ -121,7 +123,7 @@ def lookup(key, val, doc: 'Document') -> bool:

return is_empty != val
else:
return (get_key in doc.non_empty_fields) == val
return (_is_not_empty(get_key, value)) == val
else:
# return value == val
raise ValueError(
Expand Down
40 changes: 23 additions & 17 deletions docarray/document/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@
_all_mime_types = set(mimetypes.types_map.values())


def _is_not_empty(attribute, value):
if value is not None:
if attribute not in default_values:
return True
else:
dv = default_values[attribute]
if dv in (
'ChunkArray',
'MatchArray',
'DocumentArray',
list,
dict,
'Dict[str, NamedScore]',
):
if value:
return True
elif value != dv:
return True
return False


@dataclass(unsafe_hash=True, eq=False)
class DocumentData:
_reference_doc: 'Document' = field(hash=False, compare=False)
Expand Down Expand Up @@ -67,23 +88,8 @@ def _non_empty_fields(self) -> Tuple[str]:
f_name = f.name
if not f_name.startswith('_') or f_name == '_metadata':
v = getattr(self, f_name)
if v is not None:
if f_name not in default_values:
r.append(f_name)
else:
dv = default_values[f_name]
if dv in (
'ChunkArray',
'MatchArray',
'DocumentArray',
list,
dict,
'Dict[str, NamedScore]',
):
if v:
r.append(f_name)
elif v != dv:
r.append(f_name)
if _is_not_empty(f_name, v):
r.append(f_name)

return tuple(r)

Expand Down