Skip to content

Commit

Permalink
Use attrgetter rather than lambda in sort
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 6, 2024
1 parent 47c2ac3 commit 86b09df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/script/exportCalibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))

Check warning on line 174 in python/lsst/daf/butler/script/exportCalibs.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/script/exportCalibs.py#L174

Added line #L174 was not covered by tests

requiredDimensions: set[str] = set()
for ref in sortedDatasets:
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/script/queryDimensionRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from __future__ import annotations

from operator import attrgetter
from typing import Any

from astropy.table import Table
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86b09df

Please sign in to comment.