Skip to content

Commit

Permalink
Change collections.query to collections.x_query for "experimental"
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 15, 2024
1 parent 2b7b444 commit 41c84ff
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_butler_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def remove_from_chain(
raise NotImplementedError()

@abstractmethod
def query(
def x_query(
self,
expression: str | Iterable[str],
collection_types: Set[CollectionType] | CollectionType | None = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def remove_from_chain(
parent_collection_name, list(ensure_iterable(child_collection_names))
)

def query(
def x_query(
self,
expression: str | Iterable[str],
collection_types: Set[CollectionType] | CollectionType | None = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def remove_from_chain(
) -> None:
raise NotImplementedError("Not yet available")

def query(
def x_query(
self,
expression: str | Iterable[str],
collection_types: Set[CollectionType] | CollectionType | None = None,
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/collectionChain.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def collectionChain(
if flatten:
if mode not in ("redefine", "prepend", "extend"):
raise RuntimeError(f"'flatten' flag is not allowed for {mode}")
children = butler.collections.query(children, flatten_chains=True)
children = butler.collections.x_query(children, flatten_chains=True)

_modify_collection_chain(butler, mode, parent, children)

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/exportCalibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def exportCalibs(
collectionsToExport = []
datasetsToExport = []

for collection in butler.collections.query(
for collection in butler.collections.x_query(
collections_query,
flatten_chains=True,
include_chains=True,
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/daf/butler/script/queryCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _getTable(
dtype=(str, str, str),
)
butler = Butler.from_config(repo)
names = sorted(butler.collections.query(glob or "*", collection_types=frozenset(collection_type)))
names = sorted(butler.collections.x_query(glob or "*", collection_types=frozenset(collection_type)))
if inverse:
for name in names:
info = butler.collections.get_info(name, include_parents=True)
Expand Down Expand Up @@ -153,7 +153,7 @@ def addCollection(name: str, level: int = 0) -> None:
for name in info.children:
addCollection(name, level + 1)

collections = butler.collections.query(glob or "*", collection_types=frozenset(collection_type))
collections = butler.collections.x_query(glob or "*", collection_types=frozenset(collection_type))
for collection in sorted(collections):
addCollection(collection)
return table
Expand All @@ -166,7 +166,7 @@ def _getFlatten(
) -> Table:
butler = Butler.from_config(repo)
collectionNames = list(
butler.collections.query(
butler.collections.x_query(
glob or "*", collection_types=frozenset(collection_type), flatten_chains=True
)
)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/queryDataIds.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def queryDataIds(
# Need to constrain results based on dataset type and collection.
query_collections = collections or "*"

expanded_collections = butler.collections.query(query_collections)
expanded_collections = butler.collections.x_query(query_collections)

sub_query = query.join_dataset_search(dataset_types.pop(0), collections=expanded_collections)
for dt in dataset_types:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/queryDatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def getDatasets(self) -> Iterator[DatasetRef]:
# query each time.
dataset_types = self.butler.registry.queryDatasetTypes(datasetTypes)
with self.butler._query() as query:
query_collections = self.butler.collections.query(query_collections)
query_collections = self.butler.collections.x_query(query_collections)
# Accumulate over dataset types.
for dt in dataset_types:
results = query.datasets(dt, collections=query_collections, find_first=self._find_first)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/queryDimensionRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def queryDimensionRecords(

if datasets:
query_collections = collections or "*"
expanded_collections = butler.collections.query(query_collections)
expanded_collections = butler.collections.x_query(query_collections)
dataset_types = list(butler.registry.queryDatasetTypes(datasets))

sub_query = query.join_dataset_search(dataset_types.pop(0), collections=expanded_collections)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/removeCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _getCollectionInfo(
"""
butler = Butler.from_config(repo, without_datastore=True)
try:
names = sorted(butler.collections.query(collection, include_chains=True))
names = sorted(butler.collections.x_query(collection, include_chains=True))
except MissingCollectionError:
# Hide the error and act like no collections should be removed.
names = []
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/removeRuns.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _getCollectionInfo(
"""
butler = Butler.from_config(repo)
try:
collectionNames = butler.collections.query(collection, CollectionType.RUN, include_chains=False)
collectionNames = butler.collections.x_query(collection, CollectionType.RUN, include_chains=False)
except MissingCollectionError:
# Act as if no collections matched.
collectionNames = []
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/retrieveArtifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def retrieveArtifacts(
dataset_types = butler.registry.queryDatasetTypes(query_types)
refs: list[DatasetRef] = []
with butler._query() as query:
expanded_collections = butler.collections.query(query_collections)
expanded_collections = butler.collections.x_query(query_collections)
for dt in dataset_types:
results = query.datasets(dt, collections=expanded_collections, find_first=find_first)
if where:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/script/transferDatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def transferDatasets(
dataset_types = source_butler.registry.queryDatasetTypes(dataset_type_expr)
source_refs: list[DatasetRef] = []
with source_butler._query() as query:
query_collections = source_butler.collections.query(collections_expr)
query_collections = source_butler.collections.x_query(collections_expr)

Check warning on line 86 in python/lsst/daf/butler/script/transferDatasets.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/script/transferDatasets.py#L86

Added line #L86 was not covered by tests
# Loop over dataset types and accumulate.
for dt in dataset_types:
results = query.datasets(dt, collections=query_collections, find_first=find_first)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/transfers/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _computeDatasetAssociations(self) -> dict[str, list[DatasetAssociation]]:
collectionTypes = {CollectionType.TAGGED}
if datasetType.isCalibration():
collectionTypes.add(CollectionType.CALIBRATION)
resolved_collections = self._butler.collections.query(
resolved_collections = self._butler.collections.x_query(
self._collections.keys(),
collection_types=collectionTypes,
flatten_chains=False,
Expand Down

0 comments on commit 41c84ff

Please sign in to comment.