damccorm commented on code in PR #41062:
URL: https://github.com/apache/beam/pull/41062#discussion_r4513558776
##########
sdks/python/apache_beam/transforms/combiners.py:
##########
@@ -498,21 +501,24 @@ def add_input(self, accumulator, element, *args,
**kwargs):
def merge_accumulators(self, accumulators, *args, **kwargs):
result_heap = None
holds_comparables = None
+ use_comparables = self._compare is not operator.lt or bool(self._key)
+ n = self._n
for accumulator in accumulators:
holds_comparables, heap = accumulator
- if self._compare is not operator.lt or self._key:
+ if use_comparables:
heap = self._hydrated_heap(heap)
holds_comparables = True
else:
assert not holds_comparables
if result_heap is None:
- result_heap = heap
- else:
+ result_heap = list(heap)
+ elif n > 0:
Review Comment:
As noted in the comment, `heappushpop([], x)` returns `x` and leaves `heap`
empty when `n == 0`, so `result_heap` is already empty for `n == 0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]