Skip to content

Commit

Permalink
Merge pull request #724 from lsst/tickets/DM-35937
Browse files Browse the repository at this point in the history
DM-35937: Get the composite dataset type from the component dataset type
  • Loading branch information
timj committed Aug 18, 2022
2 parents bf1ffe9 + d961432 commit 6ee339d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
10 changes: 4 additions & 6 deletions python/lsst/daf/butler/registry/queries/_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ def findDatasets(
return ChainedDatasetQueryResults(
[],
doomed_by=[
f"No registered dataset type {datasetType!r} found, so no instances can "
"exist in any collection."
f"Dataset type {datasetType!r} is not registered, so no instances of it can exist in "
"any collection."
],
)
else:
Expand All @@ -426,10 +426,8 @@ def findDatasets(
)
if datasetType.isComponent():
# We were given a true DatasetType instance, but it's a component.
parentName, componentName = datasetType.nameAndComponent()
storage = self._query.managers.datasets[parentName]
datasetType = storage.datasetType
components = [componentName]
components = [datasetType.component()]
datasetType = datasetType.makeCompositeDatasetType()
else:
components = [None]
summary = QuerySummary(self.graph, whereRegion=self._query.whereRegion, datasets=[datasetType])
Expand Down
39 changes: 39 additions & 0 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,45 @@ def testQueryResults(self):
list(subsetDataIds.findDatasets(bias, collections=["imported_r", "imported_g"], findFirst=True)),
expectedDeduplicatedBiases,
)

# Check dimensions match.
with self.assertRaises(ValueError):
subsetDataIds.findDatasets("flat", collections=["imported_r", "imported_g"], findFirst=True)

# Use a component dataset type.
self.assertCountEqual(
list(
subsetDataIds.findDatasets(
bias.makeComponentDatasetType("image"),
collections=["imported_r", "imported_g"],
findFirst=False,
)
),
[ref.makeComponentRef("image") for ref in expectedAllBiases],
)

# Use a named dataset type that does not exist and a dataset type
# object that does not exist.
unknown_type = DatasetType("not_known", dimensions=bias.dimensions, storageClass="Exposure")
unknown_component_type = unknown_type.makeComponentDatasetType("image")

# Four combinations of unknown dataset type need to be tested.
# Composite and component and string name vs dataset type object.
test_type: Union[str, DatasetType]
for test_type, test_type_name in (
(unknown_type, unknown_type.name),
(unknown_type.name, unknown_type.name),
(unknown_component_type, unknown_type.name),
(unknown_component_type.name, unknown_component_type.name),
):
result = subsetDataIds.findDatasets(
test_type, collections=["imported_r", "imported_g"], findFirst=True
)
self.assertEqual(result.count(), 0)
self.assertIn(
f"Dataset type '{test_type_name}' is not registered", "\n".join(result.explain_no_results())
)

# Materialize the bias dataset queries (only) by putting the results
# into temporary tables, then repeat those tests.
with subsetDataIds.findDatasets(
Expand Down

0 comments on commit 6ee339d

Please sign in to comment.