Skip to content

Commit

Permalink
More Numpydoc fixes
Browse files Browse the repository at this point in the history
All except registry.
  • Loading branch information
timj committed Dec 8, 2023
1 parent 30a0748 commit 158f8f8
Show file tree
Hide file tree
Showing 33 changed files with 448 additions and 51 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def with_components(self, components: Sequence[str | None]) -> ParentDatasetQuer
Parameters
----------
components : `~collections.abc.Sequence` [ `str` or `None` ]
components : `~collections.abc.Sequence` [ `str` or `None` ]
Names of components to include in iteration. `None` may be
included (at most once) to include the parent dataset type.
"""
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/datastore/cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def move_to_cache(self, uri: ResourcePath, ref: DatasetRef) -> ResourcePath | No
Returns
-------
new : `lsst.resources.ResourcePath` or `None`
Always refuses and returns `None`.
Always refuses and returns `None`.
"""
return None

Expand Down
13 changes: 10 additions & 3 deletions python/lsst/daf/butler/dimensions/_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def direct(
) -> SerializedDataCoordinate:
"""Construct a `SerializedDataCoordinate` directly without validators.
Parameters
----------
dataId : `dict`
The data ID.
records : `dict` or `None`
The dimension records.
Notes
-----
This differs from the pydantic "construct" method in that the arguments
are explicitly what the model requires, and it will recurse through
members, constructing them from their corresponding `direct` methods.
Expand Down Expand Up @@ -142,9 +151,7 @@ class DataCoordinate(NamedKeyMapping[Dimension, DataIdValue]):
(instead, it is the same as testing for equality on the `required`
attribute).
See Also
--------
:ref:`lsst.daf.butler-dimensions_data_ids`
See also :ref:`lsst.daf.butler-dimensions_data_ids`
"""

__slots__ = ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class DataCoordinateSet(_DataCoordinateCollectionBase):
If `None` (default), `DataCoordinateSet.hasRecords` will be computed
from the given data IDs, immediately if ``check`` is `True`, or on
first use if ``check`` is `False`.
check: `bool`, optional
check : `bool`, optional
If `True` (default) check that all data IDs are consistent with the
given ``graph`` and state flags at construction. If `False`, no
checking will occur.
Expand Down Expand Up @@ -808,7 +808,7 @@ class DataCoordinateSequence(_DataCoordinateCollectionBase, Sequence[DataCoordin
If `None` (default), `DataCoordinateSet.hasRecords` will be computed
from the given data IDs, immediately if ``check`` is `True`, or on
first use if ``check`` is `False`.
check: `bool`, optional
check : `bool`, optional
If `True` (default) check that all data IDs are consistent with the
given ``graph`` and state flags at construction. If `False`, no
checking will occur.
Expand Down
7 changes: 6 additions & 1 deletion python/lsst/daf/butler/dimensions/_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class DatabaseTopologicalFamilyConstructionVisitor(DimensionConstructionVisitor)
----------
name : `str`
Name of the family.
space : `TopologicalSpace`
Space in which this family's regions live.
members : `~collections.abc.Iterable` [ `str` ]
The names of the members of this family, ordered according to the
priority used in `choose` (first-choice member first).
Expand Down Expand Up @@ -370,6 +372,9 @@ class DatabaseDimensionCombination(DimensionCombination, DatabaseDimensionElemen
If `True`, always include this element in any query or data ID in
which its ``required`` dimensions appear, because it defines a
relationship between those dimensions that must always be satisfied.
populated_by : `Dimension` or `None`
The dimension that this element's records are always inserted,
exported, and imported alongside.
Notes
-----
Expand Down Expand Up @@ -453,7 +458,7 @@ class DatabaseDimensionElementConstructionVisitor(DimensionConstructionVisitor):
relationship between those dimensions that must always be satisfied.
Should only be provided when a `DimensionCombination` is being
constructed.
populated_by: `Dimension`, optional
populated_by : `Dimension`, optional
The dimension that this element's records are always inserted,
exported, and imported alongside.
"""
Expand Down
85 changes: 81 additions & 4 deletions python/lsst/daf/butler/dimensions/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ class SerializedDimensionGraph(_BaseModelCompat):
def direct(cls, *, names: list[str]) -> SerializedDimensionGraph:
"""Construct a `SerializedDimensionGraph` directly without validators.
Parameters
----------
names : `list` [`str`]
The names of the dimensions to include.
Returns
-------
graph : `SerializedDimensionGraph`
Model representing these dimensions.
Notes
-----
This differs from the pydantic "construct" method in that the arguments
are explicitly what the model requires, and it will recurse through
members, constructing them from their corresponding `direct` methods.
Expand Down Expand Up @@ -174,7 +186,7 @@ def __ge__(self, other: Set[Any]) -> bool:
version="v27",
)
@immutable
class DimensionGraph:
class DimensionGraph: # numpydoc ignore=PR02
"""An immutable, dependency-complete collection of dimensions.
`DimensionGraph` is deprecated in favor of `DimensionGroup` and will be
Expand Down Expand Up @@ -404,6 +416,18 @@ def get(self, name: str, default: Any = None) -> DimensionElement:
This lookup covers all `DimensionElement` instances in
``self.elements``, not just true `Dimension` instances).
Parameters
----------
name : `str`
Name of element to return.
default : `typing.Any` or `None`
Default value if named element is not present.
Returns
-------
element : `DimensionElement` or `None`
The element found, or the default.
"""
return self.elements.get(name, default)

Expand All @@ -416,27 +440,56 @@ def __repr__(self) -> str:
def as_group(self) -> DimensionGroup:
"""Return a `DimensionGroup` that represents the same set of
dimensions.
Returns
-------
group : `DimensionGroup`
Group that represents the same set of dimensions.
"""
return self._group

def isdisjoint(self, other: DimensionGroup | DimensionGraph) -> bool:
"""Test whether the intersection of two graphs is empty.
Returns `True` if either operand is the empty.
Parameters
----------
other : `DimensionGroup` or `DimensionGraph`
Other graph to compare with.
Returns
-------
is_disjoint : `bool`
Returns `True` if either operand is the empty.
"""
return self._group.isdisjoint(other.as_group())

def issubset(self, other: DimensionGroup | DimensionGraph) -> bool:
"""Test whether all dimensions in ``self`` are also in ``other``.
Returns `True` if ``self`` is empty.
Parameters
----------
other : `DimensionGroup` or `DimensionGraph`
Other graph to compare with.
Returns
-------
is_subset : `bool`
Returns `True` if ``self`` is empty.
"""
return self._group <= other.as_group()

def issuperset(self, other: DimensionGroup | DimensionGraph) -> bool:
"""Test whether all dimensions in ``other`` are also in ``self``.
Returns `True` if ``other`` is empty.
Parameters
----------
other : `DimensionGroup` or `DimensionGraph`
Other graph to compare with.
Returns
-------
is_superset : `bool`
Returns `True` if ``other`` is empty.
"""
return self._group >= other.as_group()

Expand Down Expand Up @@ -468,6 +521,18 @@ def __gt__(self, other: DimensionGroup | DimensionGraph) -> bool:
def union(self, *others: DimensionGroup | DimensionGraph) -> DimensionGraph:
"""Construct a new graph with all dimensions in any of the operands.
Parameters
----------
*others : `DimensionGroup` or `DimensionGraph`
Other graphs to join with.
Returns
-------
union : `DimensionGraph`
The union of this graph wit hall the others.
Notes
-----
The elements of the returned graph may exceed the naive union of
their elements, as some `DimensionElement` instances are included
in graphs whenever multiple dimensions are present, and those
Expand All @@ -479,6 +544,18 @@ def union(self, *others: DimensionGroup | DimensionGraph) -> DimensionGraph:
def intersection(self, *others: DimensionGroup | DimensionGraph) -> DimensionGraph:
"""Construct a new graph with only dimensions in all of the operands.
Parameters
----------
*others : `DimensionGroup` or `DimensionGraph`
Other graphs to use.
Returns
-------
inter : `DimensionGraph`
Intersection of all the graphs.
Notes
-----
See also `union`.
"""
names = set(self.names).intersection(*[other.names for other in others])
Expand Down
83 changes: 78 additions & 5 deletions python/lsst/daf/butler/dimensions/_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class SortedSequenceSet(Set[str]):
This delegates directly to ``tuple.__contains__``, so there is an implicit
assumption that `len` is small and hence O(N) lookups are not a problem, as
is the case for sets of dimension names.
Parameters
----------
seq : `tuple` [`str`, ...]
Strings to see the set.
"""

def __init__(self, seq: tuple[str, ...]):
Expand Down Expand Up @@ -85,7 +90,13 @@ def __repr__(self) -> str:
return f"{{{', '.join(str(k) for k in self._seq)}}}"

def as_tuple(self) -> tuple[str, ...]:
"""Return the underlying tuple."""
"""Return the underlying tuple.
Returns
-------
t : `tuple`
A tuple of all the values.
"""
return self._seq

@property
Expand All @@ -101,7 +112,7 @@ def names(self) -> Set[str]:


@immutable
class DimensionGroup:
class DimensionGroup: # numpydoc ignore=PR02
"""An immutable, dependency-complete collection of dimensions.
`DimensionGroup` behaves in many respects like a set of `str` dimension
Expand Down Expand Up @@ -248,6 +259,13 @@ def __repr__(self) -> str:
def as_group(self) -> DimensionGroup:
"""Return ``self``.
Returns
-------
group : `DimensionGroup`
Returns itself.
Notes
-----
This is a backwards-compatibility API that allows both `DimensionGraph`
and `DimensionGroup` to be coerced to the latter.
"""
Expand All @@ -257,6 +275,13 @@ def as_group(self) -> DimensionGroup:
def _as_graph(self) -> DimensionGraph:
"""Return a view of ``self`` as a `DimensionGraph`.
Returns
-------
graph : `DimensionGraph`
The deprecated form of `DimensionGroup`.
Notes
-----
This is provided as a convenience for methods and properties that must
return a `DimensionGraph` for backwards compatibility (until v27). It
is the only way of making a `DimensionGraph` that does not produce
Expand All @@ -271,21 +296,45 @@ def _as_graph(self) -> DimensionGraph:
def isdisjoint(self, other: DimensionGroup) -> bool:
"""Test whether the intersection of two groups is empty.
Returns `True` if either operand is the empty.
Parameters
----------
other : `DimensionGroup`
Other group to compare with.
Returns
-------
is_disjoin : `bool`
Returns `True` if either operand is the empty.
"""
return self.names.isdisjoint(other.names)

def issubset(self, other: DimensionGroup) -> bool:
"""Test whether all dimensions in ``self`` are also in ``other``.
Returns `True` if ``self`` is empty.
Parameters
----------
other : `DimensionGroup`
Other group to compare with.
Returns
-------
is_subset : `bool`
Returns `True` if ``self`` is empty.
"""
return self.names <= other.names

def issuperset(self, other: DimensionGroup) -> bool:
"""Test whether all dimensions in ``other`` are also in ``self``.
Returns `True` if ``other`` is empty.
Parameters
----------
other : `DimensionGroup`
Other group to compare with.
Returns
-------
is_superset : `bool`
Returns `True` if ``other`` is empty.
"""
return self.names >= other.names

Expand Down Expand Up @@ -316,6 +365,18 @@ def __gt__(self, other: DimensionGroup) -> bool:
def union(self, *others: DimensionGroup) -> DimensionGroup:
"""Construct a new group with all dimensions in any of the operands.
Parameters
----------
*others : `DimensionGroup`
Other groups to join with.
Returns
-------
union : `DimensionGroup`
Union of all the groups.
Notes
-----
The elements of the returned group may exceed the naive union of their
elements, as some dimension elements are included in groups whenever
multiple dimensions are present, and those dependency dimensions could
Expand All @@ -327,6 +388,18 @@ def union(self, *others: DimensionGroup) -> DimensionGroup:
def intersection(self, *others: DimensionGroup) -> DimensionGroup:
"""Construct a new group with only dimensions in all of the operands.
Parameters
----------
*others : `DimensionGroup`
Other groups to compare with.
Returns
-------
inter : `DimensionGroup`
Intersection of all the groups.
Notes
-----
See also `union`.
"""
names = set(self.names).intersection(*[other.names for other in others])
Expand Down

0 comments on commit 158f8f8

Please sign in to comment.