Skip to content

Commit

Permalink
Fix counting of elements in loop
Browse files Browse the repository at this point in the history
Previously enumerate() was used in the loop as a proxy counter
but this was removed mistakenly when ruff complained that the
counter wasn't being used. Replace the logic with an explicit
counter so people don't get confused again.
  • Loading branch information
timj committed Aug 7, 2023
1 parent d1bbb55 commit 0e05001
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/lsst/pipe/base/graphBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,13 @@ def connectDataIds(
_LOG.debug("Iterating over query results to associate quanta with datasets.")
# Iterate over query results, populating data IDs for datasets and
# quanta and then connecting them to each other.
n = -1
n = 0 # Must count in loop since this is a lazy iterable.
for commonDataId in commonDataIds:
# Create DatasetRefs for all DatasetTypes from this result row,
# noting that we might have created some already.
# We remember both those that already existed and those that we
# create now.
n += 1
refsForRow = {}
dataIdCacheForRow: dict[DimensionGraph, DataCoordinate] = {}
for datasetType, refs in itertools.chain(
Expand Down Expand Up @@ -1123,7 +1124,7 @@ def connectDataIds(
dataId = dataIdCacheForRow[datasetType.dimensions]
ref_holder = refsForRow[datasetType.name]
quantum.outputs[datasetType.name][dataId] = ref_holder
if n < 0:
if n == 0:
_LOG.critical("Initial data ID query returned no rows, so QuantumGraph will be empty.")
emptiness_explained = False
for message in commonDataIds.explain_no_results():
Expand Down

0 comments on commit 0e05001

Please sign in to comment.