Skip to content

Commit 66c40c0

Browse files
TallJimbotimj
authored andcommitted
Add records argument to DataCoordinateIterable.standardize.
1 parent 20ae036 commit 66c40c0

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

python/lsst/daf/butler/core/_containers/_data_coordinate/_abstract_set.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
__all__ = ("DataCoordinateAbstractSet",)
2525

2626
from abc import abstractmethod
27-
from typing import AbstractSet, Any, Iterable, Optional
27+
from typing import TYPE_CHECKING, AbstractSet, Any, Iterable, Optional
2828

2929
from ...dimensions import DataCoordinate, DataId, DimensionGraph
3030
from ._collection import DataCoordinateCollection
31-
from ._iterable import DataCoordinateIterable, DataCoordinateCommonState
31+
from ._iterable import DataCoordinateCommonState, DataCoordinateIterable
32+
33+
if TYPE_CHECKING:
34+
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet
3235

3336

3437
class DataCoordinateAbstractSet(DataCoordinateCollection):
@@ -82,6 +85,7 @@ def standardize(
8285
graph: DimensionGraph,
8386
*,
8487
defaults: Optional[DataCoordinate] = None,
88+
records: Optional[HeterogeneousDimensionRecordAbstractSet] = None,
8589
**kwargs: Any,
8690
) -> DataCoordinateAbstractSet:
8791
"""Return a container with standardized versions of the given data IDs.
@@ -99,6 +103,10 @@ def standardize(
99103
Default dimension key-value pairs to use when needed. These are
100104
ignored if a different value is provided for the same key in
101105
``data_ids`` or `**kwargs``.
106+
records : `HeterogeneousDimensionRecordAbstractSet`, optional
107+
Container of `DimensionRecord` instances that may be used to
108+
fill in missing keys and/or attach records. If provided, the
109+
returned object is guaranteed to have `hasRecords` return `True`.
102110
**kwargs
103111
Additional keyword arguments are treated like additional key-value
104112
pairs in the elements of ``data_ids``, and override any already
@@ -114,7 +122,7 @@ def standardize(
114122
`DataCoordinate.standardize` on all elements in ``self``, with
115123
with deduplication guaranteed but no ordering guarantees.
116124
"""
117-
return super().standardize(data_ids, graph, default=defaults, **kwargs).toSet()
125+
return super().standardize(data_ids, graph, default=defaults, records=records, **kwargs).toSet()
118126

119127
@classmethod
120128
@abstractmethod

python/lsst/daf/butler/core/_containers/_data_coordinate/_collection.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
__all__ = ("DataCoordinateCollection",)
2525

2626
from abc import abstractmethod
27-
from typing import Any, Collection, Iterable, Iterator, Optional
27+
from typing import TYPE_CHECKING, Any, Collection, Iterable, Iterator, Optional
2828

2929
from ...dimensions import DataCoordinate, DataId, DimensionGraph
3030
from ._iterable import DataCoordinateIterable
3131

32+
if TYPE_CHECKING:
33+
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet
34+
3235

3336
class DataCoordinateCollection(Collection[DataCoordinate], DataCoordinateIterable):
3437
"""An abstract base class for homogeneous containers of data IDs."""
@@ -42,6 +45,7 @@ def standardize(
4245
graph: DimensionGraph,
4346
*,
4447
defaults: Optional[DataCoordinate] = None,
48+
records: Optional[HeterogeneousDimensionRecordAbstractSet] = None,
4549
**kwargs: Any,
4650
) -> DataCoordinateIterable:
4751
"""Return a container with standardized versions of the given data IDs.
@@ -59,6 +63,10 @@ def standardize(
5963
Default dimension key-value pairs to use when needed. These are
6064
ignored if a different value is provided for the same key in
6165
``data_ids`` or `**kwargs``.
66+
records : `HeterogeneousDimensionRecordAbstractSet`, optional
67+
Container of `DimensionRecord` instances that may be used to
68+
fill in missing keys and/or attach records. If provided, the
69+
returned object is guaranteed to have `hasRecords` return `True`.
6270
**kwargs
6371
Additional keyword arguments are treated like additional key-value
6472
pairs in the elements of ``data_ids``, and override any already
@@ -75,7 +83,7 @@ def standardize(
7583
with deduplication and/or reordering (depending on the subclass,
7684
which may make more specific guarantees).
7785
"""
78-
return super().standardize(data_ids, graph, default=defaults, **kwargs).toSequence()
86+
return super().standardize(data_ids, graph, default=defaults, records=records, **kwargs).toSequence()
7987

8088
def __iter__(self) -> Iterator[DataCoordinate]:
8189
return iter(self._unwrap())

python/lsst/daf/butler/core/_containers/_data_coordinate/_iterable.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from ...simpleQuery import SimpleQuery
3636

3737
if TYPE_CHECKING:
38+
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet
3839
from ._abstract_set import DataCoordinateAbstractSet
3940
from ._sequence import DataCoordinateSequence
4041

@@ -56,6 +57,7 @@ def standardize(
5657
graph: DimensionGraph,
5758
*,
5859
defaults: Optional[DataCoordinate] = None,
60+
records: Optional[HeterogeneousDimensionRecordAbstractSet] = None,
5961
**kwargs: Any,
6062
) -> DataCoordinateIterable:
6163
"""Return a container with standardized versions of the given data IDs.
@@ -73,6 +75,10 @@ def standardize(
7375
Default dimension key-value pairs to use when needed. These are
7476
ignored if a different value is provided for the same key in
7577
``data_ids`` or `**kwargs``.
78+
records : `HeterogeneousDimensionRecordAbstractSet`, optional
79+
Container of `DimensionRecord` instances that may be used to
80+
fill in missing keys and/or attach records. If provided, the
81+
returned object is guaranteed to have `hasRecords` return `True`.
7682
**kwargs
7783
Additional keyword arguments are treated like additional key-value
7884
pairs in the elements of ``data_ids``, and override any already
@@ -88,12 +94,20 @@ def standardize(
8894
`DataCoordinate.standardize` on all elements in ``self``, possibly
8995
with deduplication and/or reordering (depending on the subclass,
9096
which may make more specific guarantees).
97+
98+
Notes
99+
-----
100+
Subclasses should return an object of that type, with the exception
101+
of concrete classes that provide views into other containers; these
102+
should just inherit the implementation of their immediate ABC to
103+
return a similar non-view container.
91104
"""
92105
from ._iterator_adaptor import DataCoordinateIteratorAdapter
93106

94107
def gen() -> Iterator[DataCoordinate]:
95108
for data_id in data_ids:
96-
yield DataCoordinate.standardize(data_id, graph=graph, defaults=defaults, **kwargs)
109+
yield DataCoordinate.standardize(data_id, graph=graph, defaults=defaults, records=records,
110+
**kwargs)
97111

98112
return DataCoordinateIteratorAdapter(gen, graph=graph)
99113

python/lsst/daf/butler/core/_containers/_data_coordinate/_sequence.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
__all__ = ("DataCoordinateSequence",)
2525

2626
from abc import abstractmethod
27-
from typing import Any, Iterable, Optional, Sequence, overload
27+
from typing import TYPE_CHECKING, Any, Iterable, Optional, Sequence, overload
2828

2929
from ...dimensions import DataCoordinate, DataId, DimensionGraph
3030
from ._collection import DataCoordinateCollection
3131
from ._iterable import DataCoordinateCommonState
3232

33+
if TYPE_CHECKING:
34+
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet
35+
3336

3437
class DataCoordinateSequence(DataCoordinateCollection, Sequence[DataCoordinate]):
3538
"""An abstract base class for homogeneous sequence-like containers of data
@@ -45,6 +48,7 @@ def standardize(
4548
graph: DimensionGraph,
4649
*,
4750
defaults: Optional[DataCoordinate] = None,
51+
records: Optional[HeterogeneousDimensionRecordAbstractSet] = None,
4852
**kwargs: Any,
4953
) -> DataCoordinateSequence:
5054
"""Return a container with standardized versions of the given data IDs.
@@ -62,6 +66,10 @@ def standardize(
6266
Default dimension key-value pairs to use when needed. These are
6367
ignored if a different value is provided for the same key in
6468
``data_ids`` or `**kwargs``.
69+
records : `HeterogeneousDimensionRecordAbstractSet`, optional
70+
Container of `DimensionRecord` instances that may be used to
71+
fill in missing keys and/or attach records. If provided, the
72+
returned object is guaranteed to have `hasRecords` return `True`.
6573
**kwargs
6674
Additional keyword arguments are treated like additional key-value
6775
pairs in the elements of ``data_ids``, and override any already
@@ -77,7 +85,7 @@ def standardize(
7785
`DataCoordinate.standardize` on all elements in ``self``, with
7886
with no reordering but no deduplication.
7987
"""
80-
return super().standardize(data_ids, graph, default=defaults, **kwargs).toSequence()
88+
return super().standardize(data_ids, graph, default=defaults, records=records, **kwargs).toSequence()
8189

8290
@classmethod
8391
@abstractmethod

0 commit comments

Comments
 (0)