[ 
https://issues.apache.org/jira/browse/BEAM-7389?focusedWorklogId=268967&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-268967
 ]

ASF GitHub Bot logged work on BEAM-7389:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Jun/19 01:20
            Start Date: 28/Jun/19 01:20
    Worklog Time Spent: 10m 
      Work Description: tvalentyn commented on pull request #8904: [BEAM-7389] 
Add Python snippet for Partition transform
URL: https://github.com/apache/beam/pull/8904#discussion_r298423896
 
 

 ##########
 File path: 
sdks/python/apache_beam/examples/snippets/transforms/element_wise/partition_test.py
 ##########
 @@ -0,0 +1,87 @@
+# coding=utf-8
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from __future__ import absolute_import
+from __future__ import print_function
+
+import unittest
+
+import mock
+
+from apache_beam.examples.snippets.transforms.element_wise.partition import *
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+
[email protected]('apache_beam.Pipeline', TestPipeline)
+# pylint: disable=line-too-long
[email protected]('apache_beam.examples.snippets.transforms.element_wise.partition.print',
 lambda elem: elem)
+# pylint: enable=line-too-long
+class PartitionTest(unittest.TestCase):
+  def __init__(self, methodName):
+    super(PartitionTest, self).__init__(methodName)
+    # [START partitions]
+    annuals = [
+        {'icon': '🍅', 'name': 'Tomato', 'duration': 'annual'},
+    ]
+    biennials = [
+        {'icon': '🥕', 'name': 'Carrot', 'duration': 'biennial'},
+    ]
+    perennials = [
+        {'icon': '🍓', 'name': 'Strawberry', 'duration': 'perennial'},
+        {'icon': '🍆', 'name': 'Eggplant', 'duration': 'perennial'},
+        {'icon': '🥔', 'name': 'Potato', 'duration': 'perennial'},
+    ]
+    # [END partitions]
+
+    def partitions_test(actual1, actual2, actual3):
+      assert_that(actual1, equal_to(annuals), label='assert annuals')
+      assert_that(actual2, equal_to(biennials), label='assert biennials')
+      assert_that(actual3, equal_to(perennials), label='assert perennials')
+    self.partitions_test = partitions_test
+
+    # [START train_test]
+    train_dataset = [
 
 Review comment:
   1. I think we should we relax the requirement which elements fall into 
`test_dataset` and which into `train_dataset` in this scenario. The transform's 
semantic does not specify which elements of PCollection will be picked, since 
PCollections don't have an order of elements, however the test assumes a 
particular order, which may change when implementation of DirectRunner changes. 
But we can still verify an expectation that 5 elements were split into 4 + 1 
and altogether make up for the whole set of initial elements. 
   
   2. Even though we fix the seed for random, I think the generator 
implementation may change in a future version of Python, and the sequence of 
numbers with the same seed might be different on Python 3.7 and Python 3.9. How 
about we stub out the values for `random()`  via mock.patch? 
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 268967)
    Time Spent: 18h 20m  (was: 18h 10m)

> Colab examples for element-wise transforms (Python)
> ---------------------------------------------------
>
>                 Key: BEAM-7389
>                 URL: https://issues.apache.org/jira/browse/BEAM-7389
>             Project: Beam
>          Issue Type: Improvement
>          Components: website
>            Reporter: Rose Nguyen
>            Assignee: David Cavazos
>            Priority: Minor
>          Time Spent: 18h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to