Skip to content

Commit

Permalink
Merge pull request #662 from lsst/tickets/DM-34120
Browse files Browse the repository at this point in the history
DM-34120: Restore exception types raised by Butler
  • Loading branch information
andy-slac committed Mar 21, 2022
2 parents ab23b52 + 0b0c9db commit 2036ad5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 5 additions & 8 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@
CollectionType,
ConflictingDefinitionError,
DataIdError,
DataIdValueError,
DatasetIdGenEnum,
DimensionNameError,
InconsistentDataIdError,
Registry,
RegistryConfig,
RegistryDefaults,
Expand Down Expand Up @@ -843,7 +840,7 @@ def _rewrite_data_id(
never_found = set(not_dimensions) - matched_dims

if never_found:
raise DimensionNameError(f"Unrecognized keyword args given: {never_found}")
raise ValueError(f"Unrecognized keyword args given: {never_found}")

# There is a chance we have allocated a single dataId item
# to multiple dimensions. Need to decide which should be retained.
Expand Down Expand Up @@ -906,7 +903,7 @@ def _rewrite_data_id(
try:
recs = list(self.registry.queryDimensionRecords(dimensionName, dataId=newDataId))
except DataIdError:
raise DataIdValueError(
raise ValueError(
f"Could not find dimension '{dimensionName}'"
f" with dataId {newDataId} as part of comparing with"
f" record values {byRecord[dimensionName]}"
Expand All @@ -917,7 +914,7 @@ def _rewrite_data_id(
if (recval := getattr(recs[0], k)) != v:
errmsg.append(f"{k}({recval} != {v})")
if errmsg:
raise InconsistentDataIdError(
raise ValueError(
f"Dimension {dimensionName} in dataId has explicit value"
" inconsistent with records: " + ", ".join(errmsg)
)
Expand All @@ -943,12 +940,12 @@ def _rewrite_data_id(
log.debug("Received %d records from constraints of %s", len(records), str(values))
for r in records:
log.debug("- %s", str(r))
raise InconsistentDataIdError(
raise ValueError(
f"DataId specification for dimension {dimensionName} is not"
f" uniquely constrained to a single dataset by {values}."
f" Got {len(records)} results."
)
raise InconsistentDataIdError(
raise ValueError(
f"DataId specification for dimension {dimensionName} matched no"
f" records when constrained by {values}"
)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_simpleButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import astropy.time
from lsst.daf.butler import Butler, ButlerConfig, CollectionType, DatasetRef, DatasetType, Registry, Timespan
from lsst.daf.butler.registry import ConflictingDefinitionError, DataIdError, RegistryConfig, RegistryDefaults
from lsst.daf.butler.registry import ConflictingDefinitionError, RegistryConfig, RegistryDefaults
from lsst.daf.butler.tests import DatastoreMock
from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir

Expand Down Expand Up @@ -397,7 +397,7 @@ def testButlerGet(self):
({"x": "y"}, {"instrument": "Cam1", "detector": 2, "physical_filter": "Cam1-G"}),
)
for dataId, kwds in variants:
with self.assertRaises(DataIdError):
with self.assertRaises(ValueError):
butler.get("flat", dataId=dataId, collections=coll, **kwds)

def testGetCalibration(self):
Expand Down Expand Up @@ -515,7 +515,7 @@ def testGetCalibration(self):
self.assertEqual(bias3b_id, bias3b.id)

# Extra but inconsistent record values are a problem.
with self.assertRaises(DataIdError):
with self.assertRaises(ValueError):
bias3b_id, _ = butler.get(
"bias",
exposure=3,
Expand All @@ -527,15 +527,15 @@ def testGetCalibration(self):
)

# Ensure that spurious kwargs cause an exception.
with self.assertRaises(DataIdError):
with self.assertRaises(ValueError):
butler.get(
"bias",
{"exposure.obs_id": "four", "immediate": True, "detector.full_name": "Ba"},
collections="calibs",
instrument="Cam1",
)

with self.assertRaises(DataIdError):
with self.assertRaises(ValueError):
butler.get(
"bias",
day_obs=20211114,
Expand Down

0 comments on commit 2036ad5

Please sign in to comment.