Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-36303: Replace RFC-878/879 deprecations with removals #891

Merged
merged 18 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/changes/DM-36303.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Removed dataset type component query support from all Registry methods.
The main ``Registry.query*`` methods now warn if a ``components`` parameter is given and raise if it has a value other than `False`.
The components parameters will be removed completely after v27.
* Removed ``CollectionSearch`` class.
A simple `tuple` is now used for this.
1 change: 0 additions & 1 deletion python/lsst/daf/butler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
# Do not import or lift symbols from 'server' or 'server_models'.
# Import the registry subpackage directly for other symbols.
from .registry import (
CollectionSearch,
CollectionType,
MissingCollectionError,
MissingDatasetTypeError,
Expand Down
34 changes: 10 additions & 24 deletions python/lsst/daf/butler/_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"DataCoordinateQueryResults",
"DatasetQueryResults",
"DimensionRecordQueryResults",
"ParentDatasetQueryResults",
"SingleTypeDatasetQueryResults",
)

from abc import abstractmethod
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Iterable, Iterator
from contextlib import AbstractContextManager
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -422,15 +422,14 @@ class DatasetQueryResults(Iterable[DatasetRef]):
"""

@abstractmethod
def by_parent_dataset_type(self) -> Iterator[ParentDatasetQueryResults]:
"""Group results by parent dataset type.
def by_dataset_type(self) -> Iterator[SingleTypeDatasetQueryResults]:
"""Group results by dataset type.

Returns
-------
iter : `~collections.abc.Iterator` [ `ParentDatasetQueryResults` ]
iter : `~collections.abc.Iterator` [ `SingleTypeDatasetQueryResults` ]
An iterator over `DatasetQueryResults` instances that are each
responsible for a single parent dataset type (either just that
dataset type, one or more of its component dataset types, or both).
responsible for a single dataset type.
"""
raise NotImplementedError()

Expand Down Expand Up @@ -546,19 +545,19 @@ def explain_no_results(self, execute: bool = True) -> Iterable[str]:
raise NotImplementedError()


class ParentDatasetQueryResults(DatasetQueryResults):
class SingleTypeDatasetQueryResults(DatasetQueryResults):
"""An object that represents results from a query for datasets with a
single parent `DatasetType`.
"""

@abstractmethod
def materialize(self) -> AbstractContextManager[ParentDatasetQueryResults]:
def materialize(self) -> AbstractContextManager[SingleTypeDatasetQueryResults]:
# Docstring inherited from DatasetQueryResults.
raise NotImplementedError()

@property
@abstractmethod
def parent_dataset_type(self) -> DatasetType:
def dataset_type(self) -> DatasetType:
"""The parent dataset type for all datasets in this iterable
(`DatasetType`).
"""
Expand All @@ -576,20 +575,7 @@ def data_ids(self) -> DataCoordinateQueryResults:
"""
raise NotImplementedError()

@abstractmethod
def with_components(self, components: Sequence[str | None]) -> ParentDatasetQueryResults:
"""Return a new query results object for the same parent datasets but
different components.

Parameters
----------
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.
"""
raise NotImplementedError()

def expanded(self) -> ParentDatasetQueryResults:
def expanded(self) -> SingleTypeDatasetQueryResults:
# Docstring inherited from DatasetQueryResults.
raise NotImplementedError()

Expand Down
9 changes: 5 additions & 4 deletions python/lsst/daf/butler/_registry_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .registry._collection_type import CollectionType
from .registry._defaults import RegistryDefaults
from .registry.queries import DataCoordinateQueryResults, DatasetQueryResults, DimensionRecordQueryResults
from .utils import _DefaultMarker, _Marker

if TYPE_CHECKING:
from .direct_butler import DirectButler
Expand Down Expand Up @@ -281,7 +282,7 @@ def queryDatasetTypes(
self,
expression: Any = ...,
*,
components: bool | None = None,
components: bool | _Marker = _DefaultMarker,
missing: list[str] | None = None,
) -> Iterable[DatasetType]:
# Docstring inherited from a base class.
Expand Down Expand Up @@ -309,7 +310,7 @@ def queryDatasets(
dataId: DataId | None = None,
where: str = "",
findFirst: bool = False,
components: bool | None = None,
components: bool | _Marker = _DefaultMarker,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
Expand Down Expand Up @@ -337,7 +338,7 @@ def queryDataIds(
datasets: Any = None,
collections: CollectionArgType | None = None,
where: str = "",
components: bool | None = None,
components: bool | _Marker = _DefaultMarker,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
Expand All @@ -363,7 +364,7 @@ def queryDimensionRecords(
datasets: Any = None,
collections: CollectionArgType | None = None,
where: str = "",
components: bool | None = None,
components: bool | _Marker = _DefaultMarker,
bind: Mapping[str, Any] | None = None,
check: bool = True,
**kwargs: Any,
Expand Down
5 changes: 5 additions & 0 deletions python/lsst/daf/butler/cli/cmd/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@
@options_file_option()
def query_dataset_types(*args: Any, **kwargs: Any) -> None:
"""Get the dataset types in a repository."""
# Drop the components option.
components = kwargs.pop("components")
if components is not None:
comp_opt_str = "" if components else "no-"
click.echo(f"WARNING: --{comp_opt_str}components option is deprecated and will be removed after v27.")

Check warning on line 449 in python/lsst/daf/butler/cli/cmd/commands.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/cli/cmd/commands.py#L448-L449

Added lines #L448 - L449 were not covered by tests
table = script.queryDatasetTypes(*args, **kwargs)
if table:
table.pprint_all()
Expand Down
7 changes: 3 additions & 4 deletions python/lsst/daf/butler/cli/opt/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ def makeCollectionTypes(

components_option = MWOptionDecorator(
"--components/--no-components",
default=False,
default=None,
help=unwrap(
"""For --components, apply all expression patterns to
component dataset type names as well. For --no-components,
never apply patterns to components. Default is False.
Fully-specified component datasets (`str` or `DatasetType`
instances) are always included."""
never apply patterns to components. Only --no-components
is now supported. Option will be removed after v27."""
),
)

Expand Down
15 changes: 13 additions & 2 deletions python/lsst/daf/butler/direct_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,10 +1217,18 @@ def find_dataset(
actual_type = self.get_dataset_type(dataset_type)
else:
actual_type = dataset_type
data_id, kwargs = self._rewrite_data_id(data_id, actual_type, **kwargs)

# Store the component for later.
component_name = actual_type.component()
if actual_type.isComponent():
parent_type = actual_type.makeCompositeDatasetType()
else:
parent_type = actual_type

data_id, kwargs = self._rewrite_data_id(data_id, parent_type, **kwargs)

ref = self._registry.findDataset(
dataset_type,
parent_type,
data_id,
collections=collections,
timespan=timespan,
Expand All @@ -1229,8 +1237,11 @@ def find_dataset(
)
if ref is not None and dimension_records:
ref = ref.expanded(self._registry.expandDataId(ref.dataId, dimensions=ref.datasetType.dimensions))
if ref is not None and component_name:
ref = ref.makeComponentRef(component_name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is sufficient to make all the Butler.get() tests with components work. I do understand that doing this means that Butler.find_dataset is handling components but Butler.query_datasets() does not. If we don't like this the above code will have to move into _findDatasetRef.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with handling components here like this.

if ref is not None and storage_class is not None:
ref = ref.overrideStorageClass(storage_class)

return ref

def retrieveArtifacts(
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/direct_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
DirectDataCoordinateQueryResults,
DirectDatasetQueryResults,
DirectDimensionRecordQueryResults,
DirectParentDatasetQueryResults,
DirectSingleTypeDatasetQueryResults,
)
from .registry import queries as registry_queries
from .registry.sql_registry import SqlRegistry
Expand Down Expand Up @@ -103,7 +103,7 @@ def datasets(
**kwargs,
)
if isinstance(registry_query_result, registry_queries.ParentDatasetQueryResults):
return DirectParentDatasetQueryResults(registry_query_result)
return DirectSingleTypeDatasetQueryResults(registry_query_result)
else:
return DirectDatasetQueryResults(registry_query_result)

Expand Down
30 changes: 13 additions & 17 deletions python/lsst/daf/butler/direct_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
"DirectDataCoordinateQueryResults",
"DirectDatasetQueryResults",
"DirectDimensionRecordQueryResults",
"DirectParentDatasetQueryResults",
"DirectSingleTypeDatasetQueryResults",
]

import contextlib
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Iterable, Iterator
from typing import TYPE_CHECKING, Any

from ._query_results import (
DataCoordinateQueryResults,
DatasetQueryResults,
DimensionRecordQueryResults,
ParentDatasetQueryResults,
SingleTypeDatasetQueryResults,
)
from .registry import queries as registry_queries

Expand Down Expand Up @@ -165,10 +165,10 @@
def __iter__(self) -> Iterator[DatasetRef]:
return iter(self._registry_query_result)

def by_parent_dataset_type(self) -> Iterator[ParentDatasetQueryResults]:
def by_dataset_type(self) -> Iterator[SingleTypeDatasetQueryResults]:
# Docstring inherited.
for by_parent in self._registry_query_result.byParentDatasetType():
yield DirectParentDatasetQueryResults(by_parent)
yield DirectSingleTypeDatasetQueryResults(by_parent)

@contextlib.contextmanager
def materialize(self) -> Iterator[DatasetQueryResults]:
Expand All @@ -193,8 +193,8 @@
return self._registry_query_result.explain_no_results(execute=execute)


class DirectParentDatasetQueryResults(ParentDatasetQueryResults):
"""Implementation of `ParentDatasetQueryResults` using query result
class DirectSingleTypeDatasetQueryResults(SingleTypeDatasetQueryResults):
"""Implementation of `SingleTypeDatasetQueryResults` using query result
obtained from registry.

Parameters
Expand All @@ -210,18 +210,18 @@
def __iter__(self) -> Iterator[DatasetRef]:
return iter(self._registry_query_result)

def by_parent_dataset_type(self) -> Iterator[ParentDatasetQueryResults]:
def by_dataset_type(self) -> Iterator[SingleTypeDatasetQueryResults]:
# Docstring inherited.
yield self

@contextlib.contextmanager
def materialize(self) -> Iterator[ParentDatasetQueryResults]:
def materialize(self) -> Iterator[SingleTypeDatasetQueryResults]:
# Docstring inherited.
with self._registry_query_result.materialize() as result:
yield DirectParentDatasetQueryResults(result)
yield DirectSingleTypeDatasetQueryResults(result)

Check warning on line 221 in python/lsst/daf/butler/direct_query_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/direct_query_results.py#L221

Added line #L221 was not covered by tests

@property
def parent_dataset_type(self) -> DatasetType:
def dataset_type(self) -> DatasetType:
# Docstring inherited.
return self._registry_query_result.parentDatasetType

Expand All @@ -230,13 +230,9 @@
# Docstring inherited.
return DirectDataCoordinateQueryResults(self._registry_query_result.dataIds)

def with_components(self, components: Sequence[str | None]) -> ParentDatasetQueryResults:
def expanded(self) -> SingleTypeDatasetQueryResults:
# Docstring inherited.
return DirectParentDatasetQueryResults(self._registry_query_result.withComponents(components))

def expanded(self) -> ParentDatasetQueryResults:
# Docstring inherited.
return DirectParentDatasetQueryResults(self._registry_query_result.expanded())
return DirectSingleTypeDatasetQueryResults(self._registry_query_result.expanded())

Check warning on line 235 in python/lsst/daf/butler/direct_query_results.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/direct_query_results.py#L235

Added line #L235 was not covered by tests

def count(self, *, exact: bool = True, discard: bool = False) -> int:
# Docstring inherited.
Expand Down
1 change: 0 additions & 1 deletion python/lsst/daf/butler/registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from ._exceptions import *
from ._registry import *
from ._registry_factory import *
from .wildcards import CollectionSearch

# Some modules intentionally not imported, either because they are purely
# internal (e.g. nameShrinker.py) or they contain implementations that are
Expand Down
Loading
Loading