Skip to content

Commit 2d785d2

Browse files
committed
Fix: 'instrument' interpreted as filter 'in strument'
1 parent 5c5f77a commit 2d785d2

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

astroquery/eso/tests/test_eso.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,20 @@ def test_tap_url():
289289
("> 1.23", "> 1.23"),
290290
("< '5'", "< '5'"),
291291
("> '1.23'", "> '1.23'"),
292-
("like '%John%'", "like '%John%'"),
293-
("not like '%John%'", "not like '%John%'"),
294-
("in ('apple', 'mango', 'orange')", "in ('apple', 'mango', 'orange')"),
295-
("not in ('apple', 'mango', 'orange')", "not in ('apple', 'mango', 'orange')"),
296-
("in (1, 2, 3)", "in (1, 2, 3)"),
297-
("not in (1, 2, 3)", "not in (1, 2, 3)"),
292+
293+
("like '%John%'", "like '%John%'"),
294+
("not like '%John%'", "not like '%John%'"),
295+
("in ('apple', 'mango', 'orange')", "in ('apple', 'mango', 'orange')"),
296+
("not in ('apple', 'mango', 'orange')", "not in ('apple', 'mango', 'orange')"),
297+
("in (1, 2, 3)", "in (1, 2, 3)"),
298+
("not in (1, 2, 3)", "not in (1, 2, 3)"),
298299
299300
# Operator-based queries
300301
("<5", "< 5"),
301302
(">1.23", "> 1.23"),
303+
(">=1.23", ">= 1.23"),
304+
("<=1.23", "<= 1.23"),
305+
("!=1.23", "!= 1.23"),
302306
("<'5'", "< '5'"),
303307
(">'1.23'", "> '1.23'"),
304308
@@ -312,8 +316,8 @@ def test_tap_url():
312316
("like'%John%'", "= 'like'%John%''"), # pathologic case
313317
314318
# Ill-formed queries: Operator, but not sanitized. Expected to be passed through as-is
315-
("like %John%", "like %John%"),
316-
("not like %John%", "not like %John%"),
319+
("like %John%", "like %John%"),
320+
("not like %John%", "not like %John%"),
317321
("= SGR A", "= SGR A"),
318322
])
319323
def test_adql_sanitize_op_val(input_val, expected):
@@ -474,7 +478,7 @@ def test_reorder_columns(monkeypatch):
474478
columns=["id", "instrument"],
475479
column_filters={"instrument": "in ('MUSE', 'UVES')", "t_exptime": "> 100"},
476480
order_by="t_exptime"),
477-
"select id, instrument from beautiful.Stars where instrument in ('MUSE', 'UVES') "
481+
"select id, instrument from beautiful.Stars where instrument in ('MUSE', 'UVES') "
478482
"and t_exptime > 100 order by t_exptime desc"),
479483
480484
# With all params 1
@@ -497,7 +501,7 @@ def test_reorder_columns(monkeypatch):
497501
query_str_only=True,
498502
),
499503
"select top 100 target_name, s_ra, s_dec, em_min, em_max from ivoa.ObsCore "
500-
"where em_min > 4e-7 and em_max < 1.2e-6 and dataproduct_type in ('spectrum') "
504+
"where em_min > 4e-7 and em_max < 1.2e-6 and dataproduct_type in ('spectrum') "
501505
"and intersects(s_region, circle('ICRS', 180.0, -45.0, 0.05))=1 "
502506
"order by em_min desc"
503507
),
@@ -522,7 +526,7 @@ def test_reorder_columns(monkeypatch):
522526
query_str_only=True,
523527
),
524528
"select top 100 count(*) from ivoa.ObsCore "
525-
"where em_min > 4e-7 and em_max < 1.2e-6 and dataproduct_type in ('spectrum') "
529+
"where em_min > 4e-7 and em_max < 1.2e-6 and dataproduct_type in ('spectrum') "
526530
"and intersects(s_region, circle('ICRS', 180.0, -45.0, 0.05))=1"
527531
),
528532
])

astroquery/eso/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ 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 ",
118-
"not like ", "not in "}
117+
supported_operators = ["<=", ">=", "!=", "=", ">", "<",
118+
"not like ", "not in ", "not between ",
119+
"like ", "between ", "in "] # order matters
119120

120121
if not isinstance(op_val, str):
121122
return f"= {op_val}"
@@ -124,7 +125,7 @@ def _adql_sanitize_op_val(op_val):
124125
for s in supported_operators:
125126
if op_val.lower().startswith(s):
126127
operator, value = s, op_val[len(s):].strip()
127-
return f"{operator.strip()} {value}"
128+
return f"{operator} {value}"
128129

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

0 commit comments

Comments
 (0)