Skip to content

Commit

Permalink
Default CollectionInfo.parents to None
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Aug 16, 2024
1 parent 1c58667 commit 32d0753
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions python/lsst/daf/butler/_butler_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class CollectionInfo(BaseModel):
"""Documentation string associated with this collection."""
children: tuple[str, ...] = tuple()
"""Children of this collection (only if CHAINED)."""
parents: frozenset[str] = frozenset()
"""Any parents of this collection."""
parents: frozenset[str] | None = None
"""Any parents of this collection.
`None` if the parents were not requested.
"""

def __lt__(self, other: Any) -> bool:
"""Compare objects by collection name."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_info(self, name: str, include_parents: bool = False) -> CollectionInfo:
if record.type == CollectionType.CHAINED:
assert isinstance(record, ChainedCollectionRecord)
children = tuple(record.children)
parents: set[str] = set()
parents: set[str] | None = None
if include_parents:
parents = self._registry.getCollectionParentChains(name)
return CollectionInfo(name=name, type=record.type, doc=doc, parents=parents, children=children)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def get_info(self, name: str, include_parents: bool = False) -> CollectionInfo:
info = self._registry._get_collection_info(name, include_doc=True, include_parents=include_parents)
doc = info.doc or ""
children = info.children or ()
parents = info.parents or set()
return CollectionInfo(name=name, type=info.type, doc=doc, parents=parents, children=children)
return CollectionInfo(name=name, type=info.type, doc=doc, parents=info.parents, children=children)

def register(self, name: str, type: CollectionType = CollectionType.RUN, doc: str | None = None) -> bool:
raise NotImplementedError("Not yet available.")
Expand Down
1 change: 1 addition & 0 deletions python/lsst/daf/butler/script/queryCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def _getTree(
def addCollection(info: CollectionInfo, level: int = 0) -> None:
table.add_row((" " * level + info.name, info.type.name))
if inverse:
assert info.parents is not None # For mypy.
for pname in sorted(info.parents):
pinfo = butler.collections.get_info(pname, include_parents=inverse)
addCollection(pinfo, level + 1)
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 @@ -97,7 +97,7 @@ def _getCollectionInfo(
runs = []
datasets: dict[str, int] = defaultdict(int)
for collection_info in collections:
assert collection_info.type == CollectionType.RUN
assert collection_info.type == CollectionType.RUN and collection_info.parents is not None
runs.append(RemoveRun(collection_info.name, list(collection_info.parents)))
with butler._query() as query:
for dt in dataset_types:
Expand Down

0 comments on commit 32d0753

Please sign in to comment.