Skip to content

Commit

Permalink
Pin pydantic to less than 2
Browse files Browse the repository at this point in the history
  • Loading branch information
natelust committed Jul 4, 2023
1 parent 620e96b commit 80046aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
10 changes: 5 additions & 5 deletions python/lsst/pipe/base/_quantumContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get(
n_connections = len(dataset)
n_retrieved = 0
for i, (name, ref) in enumerate(dataset):
if isinstance(ref, list):
if isinstance(ref, (list, tuple)):
val = []
n_refs = len(ref)
for j, r in enumerate(ref):
Expand Down Expand Up @@ -301,7 +301,7 @@ def get(
"Completed retrieval of %d datasets from %d connections", n_retrieved, n_connections
)
return retVal
elif isinstance(dataset, list):
elif isinstance(dataset, (list, tuple)):
n_datasets = len(dataset)
retrieved = []
for i, x in enumerate(dataset):
Expand Down Expand Up @@ -363,14 +363,14 @@ def put(
)
for name, refs in dataset:
valuesAttribute = getattr(values, name)
if isinstance(refs, list):
if isinstance(refs, (list, tuple)):
if len(refs) != len(valuesAttribute):
raise ValueError(f"There must be a object to put for every Dataset ref in {name}")
for i, ref in enumerate(refs):
self._put(valuesAttribute[i], ref)
else:
self._put(valuesAttribute, refs)
elif isinstance(dataset, list):
elif isinstance(dataset, (list, tuple)):
if not isinstance(values, Sequence):
raise ValueError("Values to put must be a sequence")
if len(dataset) != len(values):
Expand Down Expand Up @@ -401,7 +401,7 @@ def _checkMembership(self, ref: list[DatasetRef] | DatasetRef, inout: set) -> No
which may be important for Quanta with lots of
`~lsst.daf.butler.DatasetRef`.
"""
if not isinstance(ref, list):
if not isinstance(ref, (list, tuple)):
ref = [ref]
for r in ref:
if (r.datasetType, r.dataId) not in inout:
Expand Down
33 changes: 8 additions & 25 deletions python/lsst/pipe/base/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,49 +1276,32 @@ def updateRun(self, run: str, *, metadata_key: str | None = None, update_graph_i
update_graph_id : `bool`, optional
If `True` then also update graph ID with a new unique value.
"""
dataset_id_map = {}

def _update_output_refs_in_place(refs: list[DatasetRef], run: str) -> None:
def _update_refs_in_place(refs: list[DatasetRef], run: str) -> None:
"""Update list of `~lsst.daf.butler.DatasetRef` with new run and
dataset IDs.
"""
new_refs = []
for ref in refs:
new_ref = DatasetRef(ref.datasetType, ref.dataId, run=run, conform=False)
dataset_id_map[ref.id] = new_ref.id
new_refs.append(new_ref)
refs[:] = new_refs

def _update_input_refs_in_place(refs: list[DatasetRef], run: str) -> None:
"""Update list of `~lsst.daf.butler.DatasetRef` with IDs from
dataset_id_map.
"""
new_refs = []
for ref in refs:
if (new_id := dataset_id_map.get(ref.id)) is not None:
new_ref = DatasetRef(ref.datasetType, ref.dataId, id=new_id, run=run, conform=False)
new_refs.append(new_ref)
else:
new_refs.append(ref)
refs[:] = new_refs
# hack the run to be replaced explicitly
object.__setattr__(ref, "run", run)

# Loop through all outputs and update their datasets.
for node in self._connectedQuanta:
for refs in node.quantum.outputs.values():
_update_output_refs_in_place(refs, run)
_update_refs_in_place(refs, run)

for refs in self._initOutputRefs.values():
_update_output_refs_in_place(refs, run)
_update_refs_in_place(refs, run)

_update_output_refs_in_place(self._globalInitOutputRefs, run)
_update_refs_in_place(self._globalInitOutputRefs, run)

# Update all intermediates from their matching outputs.
for node in self._connectedQuanta:
for refs in node.quantum.inputs.values():
_update_input_refs_in_place(refs, run)
_update_refs_in_place(refs, run)

for refs in self._initInputRefs.values():
_update_input_refs_in_place(refs, run)
_update_refs_in_place(refs, run)

if update_graph_id:
self._buildId = BuildId(f"{time.time()}-{os.getpid()}")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pyyaml >= 5.1
pydantic
pydantic < 2
numpy >= 1.17
networkx
frozendict
Expand Down

0 comments on commit 80046aa

Please sign in to comment.