From 7d0e1ca9aa6dcbb3832a397b76e1f64c648f898c Mon Sep 17 00:00:00 2001 From: "David H. Irving" Date: Fri, 6 Sep 2024 15:04:41 -0700 Subject: [PATCH] Allow negative values for ra and dec Fix an issue where ra and dec values in POINT() query expressions could not be negative. --- python/lsst/daf/butler/queries/_expression_strings.py | 2 ++ python/lsst/daf/butler/tests/butler_queries.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/python/lsst/daf/butler/queries/_expression_strings.py b/python/lsst/daf/butler/queries/_expression_strings.py index 3930b80d7a..50051c7904 100644 --- a/python/lsst/daf/butler/queries/_expression_strings.py +++ b/python/lsst/daf/butler/queries/_expression_strings.py @@ -365,5 +365,7 @@ def _get_float_literal_value(value: _VisitorResult, node: Node) -> float: return expr.value elif expr.expression_type == "int": return float(expr.value) + elif expr.expression_type == "unary" and expr.operator == "-": + return -1 * _get_float_literal_value(_ColExpr(expr.operand), node) raise InvalidQueryError(f"Expression '{node}' in POINT() is not a literal number.") diff --git a/python/lsst/daf/butler/tests/butler_queries.py b/python/lsst/daf/butler/tests/butler_queries.py index 9a57e35d33..d6520e7d4f 100644 --- a/python/lsst/daf/butler/tests/butler_queries.py +++ b/python/lsst/daf/butler/tests/butler_queries.py @@ -800,6 +800,17 @@ def _check_visit_id(query: Query) -> None: # conversion of integer to float. _check_visit_id(query.where(f"visit_detector_region.region OVERLAPS POINT({ra}, 1)")) + # Negative values are allowed for dec, since it's defined as -90 to + # 90. Tract 1, patch 4 slightly overlaps some negative dec values. + result = list(query.where("patch.region OVERLAPS POINT(0.335, -0.0000001)").data_ids(["patch"])) + self.assertEqual(len(result), 1) + id = result[0] + self.assertEqual(id["patch"], 4) + self.assertEqual(id["tract"], 1) + + # Negative ra values are also allowed. + _check_visit_id(query.where(f"POINT({ra-360}, {dec}) OVERLAPS visit_detector_region.region")) + # Substitute ra and dec values via bind instead of literals in the # string. _check_visit_id(