Skip to content

Commit

Permalink
Replace own functions with official ones (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 authored Aug 5, 2024
1 parent fa14396 commit 0294bc0
Showing 1 changed file with 15 additions and 34 deletions.
49 changes: 15 additions & 34 deletions ixmp4/db/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import operator
from types import UnionType
from typing import Any, ClassVar, Optional, Union, get_args, get_origin

Expand All @@ -8,10 +9,6 @@
from ixmp4.core.exceptions import BadFilterArguments, ProgrammingError


def exact(c, v):
return c == v


def in_(c, v):
return c.in_(v)

Expand All @@ -32,22 +29,6 @@ def notilike(c, v):
return c.notilike(escape_wildcard(v), escape="\\")


def gt(c, v):
return c > v


def lt(c, v):
return c < v


def gte(c, v):
return c >= v


def lte(c, v):
return c <= v


def escape_wildcard(v):
return v.replace("%", "\\%").replace("*", "%")

Expand Down Expand Up @@ -82,30 +63,30 @@ class String(str):
filter_func_prefix = "filter_"
lookup_map: dict[object, dict] = {
Id: {
"__root__": (int, exact),
"__root__": (int, operator.eq),
"in": (list[int], in_),
},
Float: {
"__root__": (int, exact),
"__root__": (int, operator.eq),
"in": (list[int], in_),
"gt": (int, gt),
"lt": (int, lt),
"gte": (int, gte),
"lte": (int, lte),
"gt": (int, operator.gt),
"lt": (int, operator.lt),
"gte": (int, operator.ge),
"lte": (int, operator.le),
},
Integer: {
"__root__": (int, exact),
"__root__": (int, operator.eq),
"in": (list[int], in_),
"gt": (int, gt),
"lt": (int, lt),
"gte": (int, gte),
"lte": (int, lte),
"gt": (int, operator.gt),
"lt": (int, operator.lt),
"gte": (int, operator.ge),
"lte": (int, operator.le),
},
Boolean: {
"__root__": (bool, exact),
"__root__": (bool, operator.eq),
},
String: {
"__root__": (str, exact),
"__root__": (str, operator.eq),
"in": (list[str], in_),
"like": (str, like),
"ilike": (str, ilike),
Expand Down Expand Up @@ -168,7 +149,7 @@ def lookup_func(c, v, tuples=tuples):
)
return lookups
else:
return {"__root__": (field_type, exact)}
return {"__root__": (field_type, operator.eq)}
else:
return lookup_map[field_type]

Expand Down

0 comments on commit 0294bc0

Please sign in to comment.