beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [1/2] beam git commit: PartitionFn should not access context
Date Wed, 08 Feb 2017 22:48:00 GMT
Repository: beam
Updated Branches:
  refs/heads/master a25855a9f -> c63eb7b49


PartitionFn should not access context


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/f6cdc9bf
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/f6cdc9bf
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/f6cdc9bf

Branch: refs/heads/master
Commit: f6cdc9bf902a865541215b2daa28a4e52217b42c
Parents: a25855a
Author: Sourabh Bajaj <sourabhbajaj@google.com>
Authored: Tue Feb 7 16:16:49 2017 -0800
Committer: Ahmet Altay <altay@google.com>
Committed: Wed Feb 8 14:33:14 2017 -0800

----------------------------------------------------------------------
 sdks/python/apache_beam/transforms/core.py            | 12 +++++-------
 sdks/python/apache_beam/transforms/ptransform_test.py |  4 ++--
 2 files changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/f6cdc9bf/sdks/python/apache_beam/transforms/core.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/transforms/core.py b/sdks/python/apache_beam/transforms/core.py
index e010cbd..f39b17f 100644
--- a/sdks/python/apache_beam/transforms/core.py
+++ b/sdks/python/apache_beam/transforms/core.py
@@ -525,8 +525,7 @@ class PartitionFn(WithTypeHints):
     """Specify which partition will receive this element.
 
     Args:
-      context: A DoFnProcessContext containing an element of the
-        input PCollection.
+      element: An element of the input PCollection.
       num_partitions: Number of partitions, i.e., output PCollections.
       *args: optional parameters and side inputs.
       **kwargs: optional parameters and side inputs.
@@ -559,8 +558,8 @@ class CallableWrapperPartitionFn(PartitionFn):
       raise TypeError('Expected a callable object instead of: %r' % fn)
     self._fn = fn
 
-  def partition_for(self, context, num_partitions, *args, **kwargs):
-    return self._fn(context.element, num_partitions, *args, **kwargs)
+  def partition_for(self, element, num_partitions, *args, **kwargs):
+    return self._fn(element, num_partitions, *args, **kwargs)
 
 
 class ParDo(PTransformWithSideInputs):
@@ -1179,9 +1178,8 @@ class Partition(PTransformWithSideInputs):
   class ApplyPartitionFnFn(DoFn):
     """A DoFn that applies a PartitionFn."""
 
-    def process(self, element, partitionfn, n, context=DoFn.ContextParam,
-                *args, **kwargs):
-      partition = partitionfn.partition_for(context, n, *args, **kwargs)
+    def process(self, element, partitionfn, n, *args, **kwargs):
+      partition = partitionfn.partition_for(element, n, *args, **kwargs)
       if not 0 <= partition < n:
         raise ValueError(
             'PartitionFn specified out-of-bounds partition index: '

http://git-wip-us.apache.org/repos/asf/beam/blob/f6cdc9bf/sdks/python/apache_beam/transforms/ptransform_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/transforms/ptransform_test.py b/sdks/python/apache_beam/transforms/ptransform_test.py
index 0981db5..9da692c 100644
--- a/sdks/python/apache_beam/transforms/ptransform_test.py
+++ b/sdks/python/apache_beam/transforms/ptransform_test.py
@@ -398,8 +398,8 @@ class PTransformTest(unittest.TestCase):
 
     class SomePartitionFn(beam.PartitionFn):
 
-      def partition_for(self, context, num_partitions, offset):
-        return (context.element % 3) + offset
+      def partition_for(self, element, num_partitions, offset):
+        return (element % 3) + offset
 
     pipeline = TestPipeline()
     pcoll = pipeline | 'Start' >> beam.Create([0, 1, 2, 3, 4, 5, 6, 7, 8])


Mime
View raw message