Skip to content

Commit

Permalink
Add values_tuple() accessor to DataCoordinate.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Aug 19, 2023
1 parent 905174c commit 81130bd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/lsst/daf/butler/core/dimensions/_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ def full(self) -> NamedKeyMapping[Dimension, DataIdValue]:
assert self.hasFull(), "full may only be accessed if hasFull() returns True."
return _DataCoordinateFullView(self)

@abstractmethod
def values_tuple(self) -> tuple[DataIdValue, ...]:
"""Return the required values (only) of this data ID as a tuple.
In contexts where all data IDs have the same dimensions, comparing and
hashing these tuples can be *much* faster than comparing the original
`DataCoordinate` instances.
"""
raise NotImplementedError()

@abstractmethod
def hasRecords(self) -> bool:
"""Whether this data ID contains records.
Expand Down Expand Up @@ -954,6 +964,10 @@ def hasRecords(self) -> bool:
# Docstring inherited from DataCoordinate.
return False

def values_tuple(self) -> tuple[DataIdValue, ...]:
# Docstring inherited from DataCoordinate.
return self._values[: len(self._graph.required)]

Check warning on line 969 in python/lsst/daf/butler/core/dimensions/_coordinate.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/core/dimensions/_coordinate.py#L969

Added line #L969 was not covered by tests

def _record(self, name: str) -> DimensionRecord | None:
# Docstring inherited from DataCoordinate.
raise AssertionError()
Expand Down

0 comments on commit 81130bd

Please sign in to comment.