Skip to content

Commit 296e9a4

Browse files
committed
Add 'not in' and 'not like' to supported TAP operators
1 parent 6ea7b1f commit 296e9a4

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

astroquery/eso/tests/test_eso.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,11 @@ def test_tap_url():
290290
("< '5'", "< '5'"),
291291
("> '1.23'", "> '1.23'"),
292292
("like '%John%'", "like '%John%'"),
293+
("not like '%John%'", "not like '%John%'"),
293294
("in ('apple', 'mango', 'orange')", "in ('apple', 'mango', 'orange')"),
295+
("not in ('apple', 'mango', 'orange')", "not in ('apple', 'mango', 'orange')"),
294296
("in (1, 2, 3)", "in (1, 2, 3)"),
297+
("not in (1, 2, 3)", "not in (1, 2, 3)"),
295298
296299
# Operator-based queries
297300
("<5", "< 5"),
@@ -308,6 +311,7 @@ def test_tap_url():
308311
309312
# Ill-formed queries: not sanitized but expected to be passed through as-is
310313
("like %John%", "like %John%"),
314+
("not like %John%", "not like %John%"),
311315
("= SGR A", "= SGR A"),
312316
])
313317
def test_adql_sanitize_op_val(input_val, expected):

astroquery/eso/utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,17 @@ def _adql_sanitize_op_val(op_val):
114114
returns "<operator> <value>" if operator is provided.
115115
Defaults to "= <value>" otherwise.
116116
"""
117-
supported_operators = {"=", ">", "<", "<=", ">=", "!=", "like", "between", "in"}
117+
supported_operators = {"=", ">", "<", "<=", ">=", "!=", "like", "between", "in",
118+
"not like", "not in"}
118119

119120
if not isinstance(op_val, str):
120121
return f"= {op_val}"
121122

122123
op_val = op_val.strip()
123-
parts = op_val.split(" ", 1)
124-
125-
if len(parts) == 1:
126-
for s in supported_operators:
127-
if op_val.startswith(s):
128-
operator, value = s, op_val.split(s, 1)[-1]
129-
return f"{operator} {value}"
130-
131-
if len(parts) == 2 and parts[0].lower() in supported_operators:
132-
operator, value = parts
133-
return f"{operator} {value}"
124+
for s in supported_operators:
125+
if op_val.lower().startswith(s):
126+
operator, value = s, op_val[len(s):].strip()
127+
return f"{operator} {value}"
134128

135129
# Default case: no operator. Assign "="
136130
value = op_val if (op_val.startswith("'") and op_val.endswith("'")) else f"'{op_val}'"

0 commit comments

Comments
 (0)