beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [07/11] beam git commit: Remove label guessing from CallablePTransform
Date Sat, 11 Feb 2017 01:00:20 GMT
Remove label guessing from CallablePTransform


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

Branch: refs/heads/master
Commit: e67384c89d66d9334bdfd0405cebbdb40dc428a5
Parents: 109ead9
Author: Sourabh Bajaj <sourabhbajaj@google.com>
Authored: Wed Feb 8 14:57:00 2017 -0800
Committer: Ahmet Altay <altay@google.com>
Committed: Fri Feb 10 16:59:50 2017 -0800

----------------------------------------------------------------------
 sdks/python/apache_beam/transforms/combiners_test.py |  4 +---
 sdks/python/apache_beam/transforms/ptransform.py     | 10 ++--------
 .../python/apache_beam/transforms/ptransform_test.py | 15 ++++++++++++---
 3 files changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/e67384c8/sdks/python/apache_beam/transforms/combiners_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/transforms/combiners_test.py b/sdks/python/apache_beam/transforms/combiners_test.py
index 6367dc8..6c101fe 100644
--- a/sdks/python/apache_beam/transforms/combiners_test.py
+++ b/sdks/python/apache_beam/transforms/combiners_test.py
@@ -78,12 +78,10 @@ class CombineTest(unittest.TestCase):
     result_top = pcoll | 'top' >> combine.Top.Largest(5)
     result_bot = pcoll | 'bot' >> combine.Top.Smallest(4)
     result_cmp = pcoll | 'cmp' >> combine.Top.Of(
-        'cmp',
         6,
         lambda a, b, names: len(names[a]) < len(names[b]),
         names)  # Note parameter passed to comparator.
     result_cmp_rev = pcoll | 'cmp_rev' >> combine.Top.Of(
-        'cmp',
         3,
         lambda a, b, names: len(names[a]) < len(names[b]),
         names,  # Note parameter passed to comparator.
@@ -227,7 +225,7 @@ class CombineTest(unittest.TestCase):
       pcoll = pipeline | 'start' >> Create([1, 1, 2, 2])
       for ix in xrange(9):
         assert_that(
-            pcoll | combine.Sample.FixedSizeGlobally('sample-%d' % ix, 3),
+            pcoll | 'sample-%d' % ix >> combine.Sample.FixedSizeGlobally(3),
             is_good_sample,
             label='check-%d' % ix)
 

http://git-wip-us.apache.org/repos/asf/beam/blob/e67384c8/sdks/python/apache_beam/transforms/ptransform.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/transforms/ptransform.py b/sdks/python/apache_beam/transforms/ptransform.py
index 4b2eb58..e4fbf76 100644
--- a/sdks/python/apache_beam/transforms/ptransform.py
+++ b/sdks/python/apache_beam/transforms/ptransform.py
@@ -633,15 +633,9 @@ class CallablePTransform(PTransform):
     return res
 
   def __call__(self, *args, **kwargs):
-    if args and args[0] is None:
-      label, self._args = None, args[1:]
-    elif args and isinstance(args[0], str):
-      label, self._args = args[0], args[1:]
-    else:
-      label, self._args = None, args
+    self._args = args
     self._kwargs = kwargs
-    # We know the label now, so initialize the super-class.
-    super(CallablePTransform, self).__init__(label=label)
+    super(CallablePTransform, self).__init__()
     return self
 
   def expand(self, pcoll):

http://git-wip-us.apache.org/repos/asf/beam/blob/e67384c8/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 f3291ac..e37fd43 100644
--- a/sdks/python/apache_beam/transforms/ptransform_test.py
+++ b/sdks/python/apache_beam/transforms/ptransform_test.py
@@ -686,8 +686,7 @@ class PTransformLabelsTest(unittest.TestCase):
   def test_apply_ptransform_using_decorator(self):
     pipeline = TestPipeline()
     pcoll = pipeline | 'PColl' >> beam.Create([1, 2, 3])
-    sample = SamplePTransform('*Sample*')
-    _ = pcoll | sample
+    _ = pcoll | '*Sample*' >> SamplePTransform()
     self.assertTrue('*Sample*' in pipeline.applied_labels)
     self.assertTrue('*Sample*/ToPairs' in pipeline.applied_labels)
     self.assertTrue('*Sample*/Group' in pipeline.applied_labels)
@@ -726,7 +725,17 @@ class PTransformLabelsTest(unittest.TestCase):
 
   def test_lable_propogation(self):
     self.check_label('TestMap' >> beam.Map(len), r'TestMap')
-    self.check_label('TestFilter' >> beam.Filter(len), r'TestFilter')
+    self.check_label('TestLambda' >> beam.Map(lambda x: x), r'TestLambda')
+    self.check_label('TestFlatMap' >> beam.FlatMap(list), r'TestFlatMap')
+    self.check_label('TestFilter' >> beam.Filter(sum), r'TestFilter')
+    self.check_label('TestCG' >> beam.CombineGlobally(sum), r'TestCG')
+    self.check_label('TestCPK' >> beam.CombinePerKey(sum), r'TestCPK')
+
+    class MyDoFn(beam.DoFn):
+      def process(self):
+        pass
+
+    self.check_label('TestParDo' >> beam.ParDo(MyDoFn()), r'TestParDo')
 
 
 class PTransformTestDisplayData(unittest.TestCase):


Mime
View raw message