Skip to content

Commit

Permalink
Merge pull request #120 from philvarner/pv/query-extension-operator-n…
Browse files Browse the repository at this point in the history
…ames

Fix STAC API Query Extension operator names from ne->neq, le->lte, and ge->gte
  • Loading branch information
vincentsarago authored Apr 11, 2024
2 parents 389706f + 49a7d6e commit 79248a2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Add official support for python 3.12
- Enforce required `type` key for `Collection` and `Catalog` models
- Add queryables link relation type (#123, @constantinius)
- Fix STAC API Query Extension operator names from ne->neq, le->lte, and ge->gte (#120, @philvarner)

3.0.0 (2024-01-25)
------------------
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ exclude = ["tests", ".venv"]

[tool.ruff]
line-length = 88

[tool.ruff.lint]
select = [
"C",
"E",
Expand Down
29 changes: 23 additions & 6 deletions stac_pydantic/api/extensions/query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Query Extension."""

import warnings
from enum import auto
from types import DynamicClassAttribute
from typing import Any, Callable
Expand All @@ -9,11 +12,14 @@

_OPERATIONS = {
"eq": lambda x, y: x == y,
"ne": lambda x, y: x != y,
"ne": lambda x, y: x != y, # deprecated
"neq": lambda x, y: x != y,
"lt": lambda x, y: x < y,
"le": lambda x, y: x <= y,
"le": lambda x, y: x <= y, # deprecated
"lte": lambda x, y: x <= y,
"gt": lambda x, y: x > y,
"ge": lambda x, y: x >= y,
"ge": lambda x, y: x >= y, # deprecated
"gte": lambda x, y: x >= y,
"startsWith": lambda x, y: x.startsWith(y),
"endsWith": lambda x, y: x.endsWith(y),
"contains": lambda x, y: y in x,
Expand All @@ -26,16 +32,27 @@ class Operator(str, AutoValueEnum):
"""

eq = auto()
ne = auto()
ne = auto() # deprecated
neq = auto()
lt = auto()
le = auto()
le = auto() # deprecated
lte = auto()
gt = auto()
ge = auto()
ge = auto() # deprecated
gte = auto()
startsWith = auto()
endsWith = auto()
contains = auto()

@DynamicClassAttribute
def operator(self) -> Callable[[Any, Any], bool]:
"""Return python operator"""
if self._value_ in ["ne", "ge", "le"]:
newvalue = self._value_.replace("e", "te")
warnings.warn(
f"`{self._value_}` is deprecated, please use `{newvalue}`",
DeprecationWarning,
stacklevel=3,
)

return _OPERATIONS[self._value_]

0 comments on commit 79248a2

Please sign in to comment.