Fix `beam.Filter` type hints for case where filter_fn specifies output type hint but not input type hint
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead. - [ ] Update
CHANGES.mdwith noteworthy changes. - [ ] If this contribution is large, please file an Apache Individual Contributor License Agreement.
See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.
R: @jrmccluskey
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers
@jrmccluskey with the current implementation of beam.Filter, the output pcollection type is not always the same as the input pcollection., e.g. the following would fail:
import apache_beam as beam
def is_even(num: float):
return num % 2 == 0.0
with beam.Pipeline() as pipeline:
even_nums = (
pipeline
| beam.Create([1, 2
]).with_output_types(int)
| beam.Filter(is_even))
assert even_nums.element_type is int
We could fix this by implementing Filter as a composite PTransform and just set the output pcollection element_type manually in Filter.expand. Would it be worth doing this? Not sure how many use cases rely specifically on beam.Filter being a ParDo or whether that's something we need to guarantee