Skip to content

Commit

Permalink
Fix dataset query missing implied dimensions
Browse files Browse the repository at this point in the history
Revert serialization changes in SerializedDatasetType and SerializedDataCoordinate, which caused them to drop implied dimensions.

This leads to an incorrect definition of the dataset type after deserialization, since it is missing some dimensions.  It also breaks the transfer of DatasetRefs from server to client, since it drops the values for implied dimensions in the data ID.  Per the documented behavior of dataset queries, the returned refs will have `hasFull() = True` and this behavior is relied on in tutorial notebooks.
  • Loading branch information
dhirving committed Nov 1, 2024
1 parent 6cb0823 commit b772ea0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_dataset_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def to_simple(self, minimal: bool = False) -> SerializedDatasetType:
"name": self.name,
"storageClass": self._storageClassName,
"isCalibration": self._isCalibration,
"dimensions": list(self._dimensions.required),
"dimensions": list(self._dimensions.names),
}

if self._parentStorageClassName is not None:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/dimensions/_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def to_simple(self, minimal: bool = False) -> SerializedDataCoordinate:
else:
records = None

return SerializedDataCoordinate(dataId=dict(self.required), records=records)
return SerializedDataCoordinate(dataId=dict(self.mapping), records=records)

@classmethod
def from_simple(
Expand Down
12 changes: 12 additions & 0 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ def test_simple_dataset_query(self) -> None:
butler.query_datasets("bias", "*", detector=100, instrument="Unknown", find_first=False)
self.assertIn("doomed", str(cm2.exception))

# Test for a regression of an issue where "band" was not being included
# in the data ID, despite being one of the dimensions in the "flat"
# dataset type.
refs = butler.query_datasets("flat", "imported_r", where="detector = 2", instrument="Cam1")
self.assertEqual(len(refs), 1)
flat = refs[0]
self.assertEqual(flat.datasetType.name, "flat")
self.assertEqual(flat.dataId["instrument"], "Cam1")
self.assertEqual(flat.dataId["detector"], 2)
self.assertEqual(flat.dataId["physical_filter"], "Cam1-R1")
self.assertEqual(flat.dataId["band"], "r")

def test_general_query(self) -> None:
"""Test Query.general and its result."""
butler = self.make_butler("base.yaml", "datasets.yaml")
Expand Down

0 comments on commit b772ea0

Please sign in to comment.