docarray.array.queryset.lookup module#

Originally from https://github.com/naiquevin/lookupy

The library is provided as-is under the MIT License

Copyright (c) 2013 Vineet Naik (naikvin@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docarray.array.queryset.lookup.lookup(key, val, doc)[source]#

Checks if key-val pair exists in doc using various lookup types

The lookup types are derived from the key and then used to check if the lookup holds true for the document:

>>> lookup('text__exact', 'hello', doc)

The above will return True if doc.text == ‘hello’ else False. And

>>> lookup('text_exact', '{tags__name}', doc)

will return True if doc.text == doc.tags[‘name’] else False

:param key : the field name to find :param val : object to match the value in the document against :param doc : the document to match

Return type

bool

class docarray.array.queryset.lookup.LookupTreeElem[source]#

Bases: object

Base class for a child in the lookup expression tree

evaluate(item)[source]#
class docarray.array.queryset.lookup.LookupNode(op='and', negate=False)[source]#

Bases: docarray.array.queryset.lookup.LookupTreeElem

A node (element having children) in the lookup expression tree

Typically it’s any object composed of two Q objects eg:

>>> Q(language__neq='Ruby') | Q(framework__startswith='S')
>>> ~Q(language__exact='PHP')
add_child(child)[source]#
evaluate(doc)[source]#

Evaluates the expression represented by the object for the document

:param doc : the document to match :return: returns true if lookup passed

class docarray.array.queryset.lookup.LookupLeaf(**kwargs)[source]#

Bases: docarray.array.queryset.lookup.LookupTreeElem

Class for a leaf in the lookup expression tree

evaluate(doc)[source]#

Evaluates the expression represented by the object for the document

:param doc : the document to match :return: returns true if lookup passed

docarray.array.queryset.lookup.Q#

alias of docarray.array.queryset.lookup.LookupLeaf

exception docarray.array.queryset.lookup.LookupyError[source]#

Bases: Exception

Base exception class for all exceptions raised by lookupy

docarray.array.queryset.lookup.dunder_partition(key)[source]#

Splits a dunderkey into 2 parts The first part is everything before the final double underscore The second part is after the final double underscore

>>> dunder_partition('a__b__c')
>>> ('a__b', 'c')
docarray.array.queryset.lookup.iff(precond, val, f)[source]#

If and only if the precond is True

Shortcut function for precond(val) and f(val). It is mainly used to create partial functions for commonly required preconditions

:param precond : (function) represents the precondition :param val : (mixed) value to which the functions are applied :param f : (function) the actual function

docarray.array.queryset.lookup.iff_not_none(val, f)#

If and only if the precond is True

Shortcut function for precond(val) and f(val). It is mainly used to create partial functions for commonly required preconditions

:param precond : (function) represents the precondition :param val : (mixed) value to which the functions are applied :param f : (function) the actual function

docarray.array.queryset.lookup.guard_type(classinfo, val)[source]#
docarray.array.queryset.lookup.guard_str(val)#
docarray.array.queryset.lookup.guard_list(val)#
docarray.array.queryset.lookup.guard_Q(val)#
docarray.array.queryset.lookup.guard_iter(val)[source]#