Skip to content

Commit

Permalink
Merge pull request #1112 from lsst/tickets/DM-47335
Browse files Browse the repository at this point in the history
DM-47335: Fix dataset query missing implied dimensions
  • Loading branch information
dhirving authored Nov 4, 2024
2 parents 6cb0823 + 7d49ac0 commit 89d1144
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
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
18 changes: 18 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,24 @@ 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.
#
# "band" is implied by "physical_filter", so it's technically not a
# 'required' dimension. However, the contract of query_datasets is
# that hasFull() should be true, so implied dimensions must be
# included.
refs = butler.query_datasets("flat", "imported_r", where="detector = 2", instrument="Cam1")
self.assertEqual(len(refs), 1)
flat = refs[0]
self.assertTrue(flat.dataId.hasFull())
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
14 changes: 14 additions & 0 deletions tests/test_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
DataCoordinate,
DataCoordinateSequence,
DataCoordinateSet,
DatasetType,
Dimension,
DimensionConfig,
DimensionElement,
Expand Down Expand Up @@ -411,6 +412,19 @@ def testPickling(self):
group2 = pickle.loads(pickle.dumps(group1))
self.assertIs(group1, group2)

def testSerialization(self):
# Check that dataset types round-trip correctly through serialization.
dataset_type = DatasetType(
"flat",
dimensions=["instrument", "detector", "physical_filter", "band"],
isCalibration=True,
universe=self.universe,
storageClass="int",
)
roundtripped = DatasetType.from_simple(dataset_type.to_simple(), universe=self.universe)

self.assertEqual(dataset_type, roundtripped)


@dataclass
class SplitByStateFlags:
Expand Down

0 comments on commit 89d1144

Please sign in to comment.