Skip to content

Commit

Permalink
Extend unit test to check for ingest_date in WHERE clause
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-slac committed Aug 19, 2024
1 parent c94ecbd commit 6366d3b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def test_general_query(self) -> None:

def test_query_ingest_date(self) -> None:
"""Test general query returning ingest_date field."""
before_ingest = astropy.time.Time.now()
butler = self.make_butler("base.yaml", "datasets.yaml")
dimensions = DimensionGroup(butler.dimensions, ["detector", "physical_filter"])

Expand All @@ -395,6 +396,20 @@ def test_query_ingest_date(self) -> None:
for row in rows:
self.assertIsInstance(row["flat.ingest_date"], astropy.time.Time)

# Check that WHERE accepts astropy time
with butler._query() as query:
query = query.join_dataset_search("flat", "imported_g")
query1 = query.where("flat.ingest_date < before_ingest", bind={"before_ingest": before_ingest})
rows = list(query1.general(dimensions))
self.assertEqual(len(rows), 0)
query1 = query.where("flat.ingest_date >= before_ingest", bind={"before_ingest": before_ingest})
rows = list(query1.general(dimensions))
self.assertEqual(len(rows), 3)
# Same with a time in string literal.
query1 = query.where(f"flat.ingest_date < T'mjd/{before_ingest.tai.mjd}'")
rows = list(query1.general(dimensions))
self.assertEqual(len(rows), 0)

def test_implied_union_record_query(self) -> None:
"""Test queries for a dimension ('band') that uses "implied union"
storage, in which its values are the union of the values for it in a
Expand Down

0 comments on commit 6366d3b

Please sign in to comment.