raams95 opened a new pull request, #40681:
URL: https://github.com/apache/beam/pull/40681
Fixes #19154
When `beam.Partition` is applied to a list instead of a PCollection, the
result can't be indexed with an int:
```python
>>> partitions = [0, 1, 2, 3, 4] | beam.Partition(lambda e, n: e % n, 2)
>>> partitions[0]
KeyError: "Tag 0 is not a defined output tag of <DoOutputsTuple
main_tag=None tags=('0', '1') transform=<ParDo(PTransform)
label=[ParDo(ApplyPartitionFnFn)]>>."
```
Inside a pipeline `partitions[0]` works, because
`DoOutputsTuple.__getitem__` converts int tags to strings so that partitions
can be looked up with the same ints the partition function returns. The result
of applying a transform to a list is a `_MaterializedDoOutputsTuple`, whose
`__getitem__` overrides that method without the conversion, so only
`partitions['0']` works there.
This change does the same int to string conversion in
`_MaterializedDoOutputsTuple.__getitem__`.
I added `test_partition_applied_to_list` to `ptransform_test.py`. It fails
with the `KeyError` above before the change and passes after it.
Testing:
- `pytest apache_beam/transforms/ptransform_test.py
apache_beam/pvalue_test.py apache_beam/pipeline_test.py`
- `yapf --diff` and `ruff check` on the changed files
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). (Not
needed, small change.)
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
--
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]