Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-43117: Allow exposure.day_obs in a WHERE clause #969

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions python/lsst/daf/butler/registry/queries/expressions/categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,8 @@ def categorizeElementId(universe: DimensionUniverse, name: str) -> tuple[Dimensi
elif column in element.dimensions.names:
# User said something like "patch.tract = x" or
# "tract.tract = x" instead of just "tract = x" or
# "tract.id = x", which is at least needlessly confusing and
# possibly not actually a column name, though we can guess
# what they were trying to do.
# Encourage them to clean that up and try again.
name = universe[column].primaryKey.name # type: ignore
raise RuntimeError(
f"Invalid reference to '{table}.{column}' "
f"in expression; please use '{column}' or "
f"'{column}.{name}' instead."
)
# "tract.id = x". Return the column as the element instead.
return element.dimensions[column], None
else:
return element, column
else:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,26 @@ def testButlerRewriteDataId(self) -> None:
new_metric = butler.get(datasetTypeName, dataId=dataId)
self.assertEqual(new_metric, metric)

# Check that we can find the datasets using the day_obs or the
# exposure.day_obs.
datasets_1 = list(
butler.registry.queryDatasets(
datasetType,
collections=self.default_run,
where="day_obs = dayObs AND instrument = instr",
bind={"dayObs": dayobs, "instr": "DummyCamComp"},
)
)
datasets_2 = list(
butler.registry.queryDatasets(
datasetType,
collections=self.default_run,
where="exposure.day_obs = dayObs AND instrument = instr",
bind={"dayObs": dayobs, "instr": "DummyCamComp"},
)
)
self.assertEqual(datasets_1, datasets_2)

def testGetDatasetCollectionCaching(self):
# Prior to DM-41117, there was a bug where get_dataset would throw
# MissingCollectionError if you tried to fetch a dataset that was added
Expand Down