Skip to content

Commit

Permalink
Add records argument to DataCoordinateIterable.standardize.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo authored and timj committed Jan 12, 2023
1 parent 20ae036 commit 66c40c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
__all__ = ("DataCoordinateAbstractSet",)

from abc import abstractmethod
from typing import AbstractSet, Any, Iterable, Optional
from typing import TYPE_CHECKING, AbstractSet, Any, Iterable, Optional

from ...dimensions import DataCoordinate, DataId, DimensionGraph
from ._collection import DataCoordinateCollection
from ._iterable import DataCoordinateIterable, DataCoordinateCommonState
from ._iterable import DataCoordinateCommonState, DataCoordinateIterable

if TYPE_CHECKING:
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet


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

@classmethod
@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
__all__ = ("DataCoordinateCollection",)

from abc import abstractmethod
from typing import Any, Collection, Iterable, Iterator, Optional
from typing import TYPE_CHECKING, Any, Collection, Iterable, Iterator, Optional

from ...dimensions import DataCoordinate, DataId, DimensionGraph
from ._iterable import DataCoordinateIterable

if TYPE_CHECKING:
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet


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

def __iter__(self) -> Iterator[DataCoordinate]:
return iter(self._unwrap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ...simpleQuery import SimpleQuery

if TYPE_CHECKING:
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet
from ._abstract_set import DataCoordinateAbstractSet
from ._sequence import DataCoordinateSequence

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

def gen() -> Iterator[DataCoordinate]:
for data_id in data_ids:
yield DataCoordinate.standardize(data_id, graph=graph, defaults=defaults, **kwargs)
yield DataCoordinate.standardize(data_id, graph=graph, defaults=defaults, records=records,
**kwargs)

return DataCoordinateIteratorAdapter(gen, graph=graph)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
__all__ = ("DataCoordinateSequence",)

from abc import abstractmethod
from typing import Any, Iterable, Optional, Sequence, overload
from typing import TYPE_CHECKING, Any, Iterable, Optional, Sequence, overload

from ...dimensions import DataCoordinate, DataId, DimensionGraph
from ._collection import DataCoordinateCollection
from ._iterable import DataCoordinateCommonState

if TYPE_CHECKING:
from .._dimension_record import HeterogeneousDimensionRecordAbstractSet


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

@classmethod
@abstractmethod
Expand Down

0 comments on commit 66c40c0

Please sign in to comment.