diff --git a/python/lsst/daf/butler/script/exportCalibs.py b/python/lsst/daf/butler/script/exportCalibs.py index 7e802e736d..8faadaef78 100644 --- a/python/lsst/daf/butler/script/exportCalibs.py +++ b/python/lsst/daf/butler/script/exportCalibs.py @@ -29,6 +29,7 @@ import logging import os from collections.abc import Iterable +from operator import attrgetter from typing import TYPE_CHECKING from astropy.table import Table @@ -170,7 +171,7 @@ def exportCalibs( log.info("Saving %d dataset(s)", len(datasetsToExport)) export.saveDatasets(datasetsToExport) - sortedDatasets = sorted(datasetsToExport, key=lambda x: x.datasetType.name) + sortedDatasets = sorted(datasetsToExport, key=attrgetter("datasetType.name", "dataId")) requiredDimensions: set[str] = set() for ref in sortedDatasets: diff --git a/python/lsst/daf/butler/script/queryDimensionRecords.py b/python/lsst/daf/butler/script/queryDimensionRecords.py index abbdc92ad3..ee8ad09995 100644 --- a/python/lsst/daf/butler/script/queryDimensionRecords.py +++ b/python/lsst/daf/butler/script/queryDimensionRecords.py @@ -27,6 +27,7 @@ from __future__ import annotations +from operator import attrgetter from typing import Any from astropy.table import Table @@ -104,7 +105,7 @@ def queryDimensionRecords( if not order_by: # use the dataId to sort the rows if not ordered already - records.sort(key=lambda r: r.dataId) + records.sort(key=attrgetter("dataId")) # order the columns the same as the record's `field.names`, and add units # to timespans