Skip to content

Operator

lumi_filter.operator

Generic operators for filtering operations.

This module provides generic operator functions for filtering operations that work across different data sources and backends.

generic_ilike_operator(left, right)

Case-insensitive contains operator.

Parameters:

Name Type Description Default
left

The value to search in

required
right

The value to search for

required

Returns:

Name Type Description
bool

True if right is contained in left (case-insensitive)

Source code in lumi_filter/operator.py
21
22
23
24
25
26
27
28
29
30
31
def generic_ilike_operator(left, right):
    """Case-insensitive contains operator.

    Args:
        left: The value to search in
        right: The value to search for

    Returns:
        bool: True if right is contained in left (case-insensitive)
    """
    return str(right).lower() in str(left).lower()

generic_in_operator(left, right)

Generic membership operator.

Checks if left value is a member of right iterable. Falls back to equality check if right is not iterable.

Parameters:

Name Type Description Default
left

The value to check for membership

required
right

The iterable to check membership in

required

Returns:

Name Type Description
bool

True if left is in right, otherwise False

Source code in lumi_filter/operator.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def generic_in_operator(left, right):
    """Generic membership operator.

    Checks if left value is a member of right iterable.
    Falls back to equality check if right is not iterable.

    Args:
        left: The value to check for membership
        right: The iterable to check membership in

    Returns:
        bool: True if left is in right, otherwise False
    """
    try:
        return left in right
    except TypeError:
        # If right isn't iterable, fall back to equality
        return left == right

generic_is_null_operator(left, right)

Generic null check operator for iterables.

Parameters:

Name Type Description Default
left

The value to check for null

required
right

String value ('true' or 'false') indicating null check type

required

Returns:

Name Type Description
bool

True if null check condition is met

Source code in lumi_filter/operator.py
83
84
85
86
87
88
89
90
91
92
93
94
def generic_is_null_operator(left, right):
    """Generic null check operator for iterables.

    Args:
        left: The value to check for null
        right: String value ('true' or 'false') indicating null check type

    Returns:
        bool: True if null check condition is met
    """
    is_null_check = right == "true"
    return (left is None) if is_null_check else (left is not None)

generic_like_operator(left, right)

Case-sensitive contains operator.

Parameters:

Name Type Description Default
left

The value to search in

required
right

The value to search for

required

Returns:

Name Type Description
bool

True if right is contained in left (case-sensitive)

Source code in lumi_filter/operator.py
 8
 9
10
11
12
13
14
15
16
17
18
def generic_like_operator(left, right):
    """Case-sensitive contains operator.

    Args:
        left: The value to search in
        right: The value to search for

    Returns:
        bool: True if right is contained in left (case-sensitive)
    """
    return str(right) in str(left)

is_null_operator(field, value)

Peewee null check operator.

Parameters:

Name Type Description Default
field

The Peewee field to check

required
value

String value ('true' or 'false') indicating null check

required

Returns:

Type Description

Peewee expression for null check

Source code in lumi_filter/operator.py
70
71
72
73
74
75
76
77
78
79
80
def is_null_operator(field, value):
    """Peewee null check operator.

    Args:
        field: The Peewee field to check
        value: String value ('true' or 'false') indicating null check

    Returns:
        Peewee expression for null check
    """
    return field.is_null(value == "true")

operator_curry(operator_name)

Create a curried operator function for peewee fields.

Parameters:

Name Type Description Default
operator_name str

Name of the operator method to curry

required

Returns:

Name Type Description
function

Curried operator function

Source code in lumi_filter/operator.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def operator_curry(operator_name):
    """Create a curried operator function for peewee fields.

    Args:
        operator_name (str): Name of the operator method to curry

    Returns:
        function: Curried operator function
    """

    def inner(field, value):
        return getattr(field, operator_name)(value)

    return inner