Skip to content

Commit

Permalink
Allow negative values for ra and dec
Browse files Browse the repository at this point in the history
Fix an issue where ra and dec values in POINT() query expressions could not be negative.
  • Loading branch information
dhirving committed Sep 6, 2024
1 parent 767a556 commit ca4876b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/queries/_expression_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
11 changes: 11 additions & 0 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ca4876b

Please sign in to comment.