Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish FlatMapTuple and MapTuple docstrings #33316

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions sdks/python/apache_beam/transforms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,15 +2117,13 @@ def MapTuple(fn, *args, **kwargs): # pylint: disable=invalid-name
r""":func:`MapTuple` is like :func:`Map` but expects tuple inputs and
flattens them into multiple input arguments.

beam.MapTuple(lambda a, b, ...: ...)

In other words

beam.MapTuple(fn)
"SwapKV" >> beam.Map(lambda kv: (kv[1], kv[0]))

is equivalent to

beam.Map(lambda element, ...: fn(\*element, ...))
"SwapKV" >> beam.MapTuple(lambda k, v: (v, k))

This can be useful when processing a PCollection of tuples
(e.g. key-value pairs).
Expand Down Expand Up @@ -2191,19 +2189,13 @@ def FlatMapTuple(fn, *args, **kwargs): # pylint: disable=invalid-name
r""":func:`FlatMapTuple` is like :func:`FlatMap` but expects tuple inputs and
flattens them into multiple input arguments.

beam.FlatMapTuple(lambda a, b, ...: ...)

is equivalent to Python 2

beam.FlatMap(lambda (a, b, ...), ...: ...)

In other words

beam.FlatMapTuple(fn)
beam.FlatMap(lambda start_end: range(start_end[0], start_end[1]))

is equivalent to

beam.FlatMap(lambda element, ...: fn(\*element, ...))
beam.FlatMapTuple(lambda start, end: range(start, end))

This can be useful when processing a PCollection of tuples
(e.g. key-value pairs).
Expand Down
Loading