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
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,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite hard to add deprecation warning on Enums 😓 so for now I think adding a warning on the operator method is a least we can do


return _OPERATIONS[self._value_]