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-47335: Fix dataset query missing implied dimensions #1112

Merged
merged 2 commits into from
Nov 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading