[
https://issues.apache.org/jira/browse/BEAM-3998?focusedWorklogId=113899&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-113899
]
ASF GitHub Bot logged work on BEAM-3998:
----------------------------------------
Author: ASF GitHub Bot
Created on: 20/Jun/18 19:31
Start Date: 20/Jun/18 19:31
Worklog Time Spent: 10m
Work Description: charlesccychen closed pull request #5652: [BEAM-3998]
Futurize examples subpackage
URL: https://github.com/apache/beam/pull/5652
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/python/apache_beam/examples/__init__.py
b/sdks/python/apache_beam/examples/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/__init__.py
+++ b/sdks/python/apache_beam/examples/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/examples/complete/__init__.py
b/sdks/python/apache_beam/examples/complete/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/complete/__init__.py
+++ b/sdks/python/apache_beam/examples/complete/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/examples/complete/autocomplete.py
b/sdks/python/apache_beam/examples/complete/autocomplete.py
index b556e65724c..d9717bad85b 100644
--- a/sdks/python/apache_beam/examples/complete/autocomplete.py
+++ b/sdks/python/apache_beam/examples/complete/autocomplete.py
@@ -22,6 +22,7 @@
import argparse
import logging
import re
+from builtins import range
import apache_beam as beam
from apache_beam.io import ReadFromText
diff --git a/sdks/python/apache_beam/examples/complete/autocomplete_test.py
b/sdks/python/apache_beam/examples/complete/autocomplete_test.py
index 888ce44dad4..792f6d0402c 100644
--- a/sdks/python/apache_beam/examples/complete/autocomplete_test.py
+++ b/sdks/python/apache_beam/examples/complete/autocomplete_test.py
@@ -17,6 +17,8 @@
"""Test for the autocomplete example."""
+from __future__ import absolute_import
+
import unittest
import apache_beam as beam
diff --git a/sdks/python/apache_beam/examples/complete/estimate_pi.py
b/sdks/python/apache_beam/examples/complete/estimate_pi.py
index 982faaa0f47..332346260c1 100644
--- a/sdks/python/apache_beam/examples/complete/estimate_pi.py
+++ b/sdks/python/apache_beam/examples/complete/estimate_pi.py
@@ -25,11 +25,14 @@
"""
from __future__ import absolute_import
+from __future__ import division
import argparse
import json
import logging
import random
+from builtins import object
+from builtins import range
import apache_beam as beam
from apache_beam.io import WriteToText
diff --git a/sdks/python/apache_beam/examples/complete/estimate_pi_test.py
b/sdks/python/apache_beam/examples/complete/estimate_pi_test.py
index 34633132e41..78376b6e05b 100644
--- a/sdks/python/apache_beam/examples/complete/estimate_pi_test.py
+++ b/sdks/python/apache_beam/examples/complete/estimate_pi_test.py
@@ -17,6 +17,8 @@
"""Test for the estimate_pi example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/complete/game/__init__.py
b/sdks/python/apache_beam/examples/complete/game/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/complete/game/__init__.py
+++ b/sdks/python/apache_beam/examples/complete/game/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/examples/complete/game/game_stats.py
b/sdks/python/apache_beam/examples/complete/game/game_stats.py
index 11b81fe1bd2..e37076424a7 100644
--- a/sdks/python/apache_beam/examples/complete/game/game_stats.py
+++ b/sdks/python/apache_beam/examples/complete/game/game_stats.py
@@ -71,6 +71,7 @@
"""
from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import argparse
@@ -229,7 +230,7 @@ def expand(self, user_scores):
class UserSessionActivity(beam.DoFn):
"""Calculate and output an element's session duration, in seconds."""
def process(self, elem, window=beam.DoFn.WindowParam):
- yield (window.end.micros - window.start.micros) / 1000000
+ yield (window.end.micros - window.start.micros)//1000000
def run(argv=None):
diff --git a/sdks/python/apache_beam/examples/complete/game/game_stats_test.py
b/sdks/python/apache_beam/examples/complete/game/game_stats_test.py
index 971f9dc9e29..209f0cf8800 100644
--- a/sdks/python/apache_beam/examples/complete/game/game_stats_test.py
+++ b/sdks/python/apache_beam/examples/complete/game/game_stats_test.py
@@ -17,6 +17,8 @@
"""Test for the game_stats example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git
a/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py
b/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py
index e99ab23ec67..d736cf50fce 100644
--- a/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py
+++ b/sdks/python/apache_beam/examples/complete/game/hourly_team_score.py
@@ -65,6 +65,7 @@
"""
from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import argparse
diff --git
a/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py
b/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py
index 9c30127d741..8c2497a883c 100644
--- a/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py
+++ b/sdks/python/apache_beam/examples/complete/game/hourly_team_score_test.py
@@ -17,6 +17,8 @@
"""Test for the user_score example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/complete/game/leader_board.py
b/sdks/python/apache_beam/examples/complete/game/leader_board.py
index 27ef16dd5d5..a92eaae8691 100644
--- a/sdks/python/apache_beam/examples/complete/game/leader_board.py
+++ b/sdks/python/apache_beam/examples/complete/game/leader_board.py
@@ -79,6 +79,7 @@
"""
from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import argparse
diff --git
a/sdks/python/apache_beam/examples/complete/game/leader_board_test.py
b/sdks/python/apache_beam/examples/complete/game/leader_board_test.py
index aece2649b89..3aad052fe71 100644
--- a/sdks/python/apache_beam/examples/complete/game/leader_board_test.py
+++ b/sdks/python/apache_beam/examples/complete/game/leader_board_test.py
@@ -17,6 +17,8 @@
"""Test for the leader_board example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/complete/game/user_score.py
b/sdks/python/apache_beam/examples/complete/game/user_score.py
index 5b13eeca7a3..7e1a07d8a85 100644
--- a/sdks/python/apache_beam/examples/complete/game/user_score.py
+++ b/sdks/python/apache_beam/examples/complete/game/user_score.py
@@ -54,6 +54,7 @@
"""
from __future__ import absolute_import
+from __future__ import division
import argparse
import csv
@@ -87,7 +88,7 @@ def process(self, elem):
'user': row[0],
'team': row[1],
'score': int(row[2]),
- 'timestamp': int(row[3]) / 1000.0,
+ 'timestamp': int(row[3]) /1000.0,
}
except: # pylint: disable=bare-except
# Log and count parse errors
diff --git a/sdks/python/apache_beam/examples/complete/game/user_score_test.py
b/sdks/python/apache_beam/examples/complete/game/user_score_test.py
index 59903d98546..f41006fd0a1 100644
--- a/sdks/python/apache_beam/examples/complete/game/user_score_test.py
+++ b/sdks/python/apache_beam/examples/complete/game/user_score_test.py
@@ -17,6 +17,8 @@
"""Test for the user_score example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/complete/juliaset/__init__.py
b/sdks/python/apache_beam/examples/complete/juliaset/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/__init__.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git
a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py
b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git
a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py
b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py
index 1beffeef9b1..f861e48403b 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset.py
@@ -21,8 +21,10 @@
"""
from __future__ import absolute_import
+from __future__ import division
import argparse
+from builtins import range
import apache_beam as beam
from apache_beam.io import WriteToText
@@ -70,7 +72,7 @@ def generate_julia_set_visualization(data, n, max_iterations):
xy = np.zeros((n, n, 3), dtype=np.uint8)
for x, y, iteration in data:
- xy[x, y] = colors[iteration * len(colors) / max_iterations]
+ xy[x, y] = colors[iteration * len(colors) // max_iterations]
return xy
diff --git
a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py
b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py
index e4986271e94..a7bc0f9208f 100644
---
a/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py
+++
b/sdks/python/apache_beam/examples/complete/juliaset/juliaset/juliaset_test.py
@@ -17,6 +17,8 @@
"""Test for the juliaset example."""
+from __future__ import absolute_import
+
import logging
import os
import re
diff --git
a/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py
b/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py
index 7289b04b07c..9d727726f66 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/juliaset_main.py
@@ -47,6 +47,8 @@
"""
+from __future__ import absolute_import
+
import logging
from apache_beam.examples.complete.juliaset.juliaset import juliaset
diff --git a/sdks/python/apache_beam/examples/complete/juliaset/setup.py
b/sdks/python/apache_beam/examples/complete/juliaset/setup.py
index 2fcde7d3485..0aa730e9549 100644
--- a/sdks/python/apache_beam/examples/complete/juliaset/setup.py
+++ b/sdks/python/apache_beam/examples/complete/juliaset/setup.py
@@ -24,6 +24,8 @@
This behavior is triggered by specifying the --setup_file command line option
when running the workflow for remote execution.
"""
+
+from __future__ import absolute_import
from __future__ import print_function
import subprocess
diff --git a/sdks/python/apache_beam/examples/complete/tfidf.py
b/sdks/python/apache_beam/examples/complete/tfidf.py
index 20ad344e96a..3eeb898b20a 100644
--- a/sdks/python/apache_beam/examples/complete/tfidf.py
+++ b/sdks/python/apache_beam/examples/complete/tfidf.py
@@ -22,6 +22,7 @@
"""
from __future__ import absolute_import
+from __future__ import division
import argparse
import glob
diff --git a/sdks/python/apache_beam/examples/complete/tfidf_test.py
b/sdks/python/apache_beam/examples/complete/tfidf_test.py
index 637d10a0df6..159407effc5 100644
--- a/sdks/python/apache_beam/examples/complete/tfidf_test.py
+++ b/sdks/python/apache_beam/examples/complete/tfidf_test.py
@@ -17,6 +17,8 @@
"""Test for the TF-IDF example."""
+from __future__ import absolute_import
+
import logging
import os
import re
diff --git
a/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py
b/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py
index a0b368f6035..fcef981c9b6 100644
--- a/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py
+++ b/sdks/python/apache_beam/examples/complete/top_wikipedia_sessions_test.py
@@ -17,6 +17,8 @@
"""Test for the top wikipedia sessions example."""
+from __future__ import absolute_import
+
import json
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/__init__.py
b/sdks/python/apache_beam/examples/cookbook/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/cookbook/__init__.py
+++ b/sdks/python/apache_beam/examples/cookbook/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py
b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py
index 91ddf51827b..e1494514262 100644
--- a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py
+++ b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input.py
@@ -27,8 +27,11 @@
a word that should be ignored when forming groups.
"""
+from __future__ import absolute_import
+
import argparse
import logging
+from builtins import range
from random import randrange
import apache_beam as beam
@@ -46,7 +49,7 @@ def attach_corpus_fn(group, corpus, ignore):
selected = None
len_corpus = len(corpus)
while not selected:
- c = corpus[randrange(0, len_corpus - 1)].values()[0]
+ c = list(corpus[randrange(0, len_corpus - 1)].values())[0]
if c != ignore:
selected = c
@@ -56,7 +59,7 @@ def attach_word_fn(group, words, ignore):
selected = None
len_words = len(words)
while not selected:
- c = words[randrange(0, len_words - 1)].values()[0]
+ c = list(words[randrange(0, len_words - 1)].values())[0]
if c != ignore:
selected = c
diff --git
a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py
b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py
index 964b35b3f08..11fb95b055c 100644
--- a/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/bigquery_side_input_test.py
@@ -17,6 +17,8 @@
"""Test for the BigQuery side input example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git
a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py
b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py
index 96128490804..b7e90839ffa 100644
--- a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py
@@ -17,9 +17,12 @@
"""End-to-end test for Bigquery tornadoes example."""
+from __future__ import absolute_import
+
import logging
import time
import unittest
+from builtins import round
from hamcrest.core.core.allof import all_of
from nose.plugins.attrib import attr
diff --git
a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py
b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py
index 45dcabaf853..cad34d814b3 100644
--- a/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_test.py
@@ -17,6 +17,8 @@
"""Test for the BigQuery tornadoes example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/coders.py
b/sdks/python/apache_beam/examples/cookbook/coders.py
index f97b0f2d9c9..b0f2a2b65e1 100644
--- a/sdks/python/apache_beam/examples/cookbook/coders.py
+++ b/sdks/python/apache_beam/examples/cookbook/coders.py
@@ -33,6 +33,7 @@
import argparse
import json
import logging
+from builtins import object
import apache_beam as beam
from apache_beam.io import ReadFromText
diff --git a/sdks/python/apache_beam/examples/cookbook/coders_test.py
b/sdks/python/apache_beam/examples/cookbook/coders_test.py
index 988d3c9d25e..7a3b7f87679 100644
--- a/sdks/python/apache_beam/examples/cookbook/coders_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/coders_test.py
@@ -17,6 +17,8 @@
"""Test for the coders example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/combiners_test.py
b/sdks/python/apache_beam/examples/cookbook/combiners_test.py
index ee1fb7765d4..15714c0051e 100644
--- a/sdks/python/apache_beam/examples/cookbook/combiners_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/combiners_test.py
@@ -23,6 +23,8 @@
checked directly on the last PCollection produced.
"""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git
a/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py
b/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py
index 7aaccb4ac1c..7620dae30bd 100644
--- a/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/custom_ptransform_test.py
@@ -17,6 +17,8 @@
"""Tests for the various custom Count implementation examples."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
index 8040ab142fd..d09a46a14d5 100644
--- a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
+++ b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
@@ -67,12 +67,12 @@
import logging
import re
import uuid
+from builtins import object
from google.cloud.proto.datastore.v1 import entity_pb2
from google.cloud.proto.datastore.v1 import query_pb2
from googledatastore import helper as datastore_helper
from googledatastore import PropertyFilter
-import six
import apache_beam as beam
from apache_beam.io import ReadFromText
@@ -83,6 +83,11 @@
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class WordExtractingDoFn(beam.DoFn):
"""Parse each line of input text into words."""
@@ -132,7 +137,7 @@ def make_entity(self, content):
datastore_helper.add_key_path(entity.key, self._kind, self._ancestor,
self._kind, str(uuid.uuid4()))
- datastore_helper.add_properties(entity, {"content":
six.text_type(content)})
+ datastore_helper.add_properties(entity, {"content": unicode(content)})
return entity
@@ -187,7 +192,7 @@ def count_ones(word_ones):
counts = (lines
| 'split' >> (beam.ParDo(WordExtractingDoFn())
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| 'group' >> beam.GroupByKey()
| 'count' >> beam.Map(count_ones))
diff --git a/sdks/python/apache_beam/examples/cookbook/filters_test.py
b/sdks/python/apache_beam/examples/cookbook/filters_test.py
index fd49f938742..5187a2feb93 100644
--- a/sdks/python/apache_beam/examples/cookbook/filters_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/filters_test.py
@@ -17,6 +17,8 @@
"""Test for the filters example."""
+from __future__ import absolute_import
+
import logging
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/group_with_coder.py
b/sdks/python/apache_beam/examples/cookbook/group_with_coder.py
index d5dbecff6bd..f9c37881762 100644
--- a/sdks/python/apache_beam/examples/cookbook/group_with_coder.py
+++ b/sdks/python/apache_beam/examples/cookbook/group_with_coder.py
@@ -30,6 +30,7 @@
import argparse
import logging
import sys
+from builtins import object
import apache_beam as beam
from apache_beam import coders
diff --git a/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py
b/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py
index ed38b5d8a4e..522333e570e 100644
--- a/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/group_with_coder_test.py
@@ -17,6 +17,8 @@
"""Test for the custom coders example."""
+from __future__ import absolute_import
+
import logging
import tempfile
import unittest
diff --git a/sdks/python/apache_beam/examples/cookbook/mergecontacts.py
b/sdks/python/apache_beam/examples/cookbook/mergecontacts.py
index 237d4ca6efd..79e7274663e 100644
--- a/sdks/python/apache_beam/examples/cookbook/mergecontacts.py
+++ b/sdks/python/apache_beam/examples/cookbook/mergecontacts.py
@@ -34,6 +34,7 @@
import argparse
import logging
import re
+from builtins import next
import apache_beam as beam
from apache_beam.io import ReadFromText
diff --git a/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py
b/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py
index 32a3d518861..8c7144bbfa7 100644
--- a/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/mergecontacts_test.py
@@ -17,6 +17,8 @@
"""Test for the mergecontacts example."""
+from __future__ import absolute_import
+
import logging
import tempfile
import unittest
diff --git
a/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py
b/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py
index 1051106ea9b..78e02e71602 100644
--- a/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py
+++ b/sdks/python/apache_beam/examples/cookbook/multiple_output_pardo_test.py
@@ -17,6 +17,8 @@
"""Test for the multiple_output_pardo example."""
+from __future__ import absolute_import
+
import logging
import re
import tempfile
diff --git a/sdks/python/apache_beam/examples/hourly_team_score_it_test.py
b/sdks/python/apache_beam/examples/hourly_team_score_it_test.py
index ffea48e524e..e46bf47e0be 100644
--- a/sdks/python/apache_beam/examples/hourly_team_score_it_test.py
+++ b/sdks/python/apache_beam/examples/hourly_team_score_it_test.py
@@ -30,6 +30,8 @@
"""
+from __future__ import absolute_import
+
import logging
import time
import unittest
diff --git a/sdks/python/apache_beam/examples/leader_board_it_test.py
b/sdks/python/apache_beam/examples/leader_board_it_test.py
index 12c3972ef0f..44297bda7bf 100644
--- a/sdks/python/apache_beam/examples/leader_board_it_test.py
+++ b/sdks/python/apache_beam/examples/leader_board_it_test.py
@@ -30,10 +30,13 @@
"""
+from __future__ import absolute_import
+
import logging
import time
import unittest
import uuid
+from builtins import range
from hamcrest.core.core.allof import all_of
from nose.plugins.attrib import attr
@@ -95,7 +98,7 @@ def _inject_pubsub_game_events(self, topic, message_count):
logging.debug('Injecting %d game events to topic %s',
message_count, topic.full_name)
- for _ in xrange(message_count):
+ for _ in range(message_count):
topic.publish(self.INPUT_EVENT % self._test_timestamp)
def _cleanup_pubsub(self):
diff --git a/sdks/python/apache_beam/examples/snippets/__init__.py
b/sdks/python/apache_beam/examples/snippets/__init__.py
index cce3acad34a..6569e3fe5de 100644
--- a/sdks/python/apache_beam/examples/snippets/__init__.py
+++ b/sdks/python/apache_beam/examples/snippets/__init__.py
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/examples/snippets/snippets.py
b/sdks/python/apache_beam/examples/snippets/snippets.py
index 2e648209179..161a67b037f 100644
--- a/sdks/python/apache_beam/examples/snippets/snippets.py
+++ b/sdks/python/apache_beam/examples/snippets/snippets.py
@@ -29,10 +29,12 @@
prefix the PATH_TO_HTML where they are included followed by a descriptive
string. The tags can contain only letters, digits and _.
"""
+from __future__ import absolute_import
+from __future__ import division
import argparse
-
-import six
+from builtins import object
+from builtins import range
import apache_beam as beam
from apache_beam.io import iobase
@@ -53,6 +55,11 @@
# pylint:disable=unused-variable
# pylint:disable=wrong-import-order, wrong-import-position
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class SnippetUtils(object):
from apache_beam.pipeline import PipelineVisitor
@@ -1048,7 +1055,7 @@ def to_entity(content):
entity = entity_pb2.Entity()
googledatastore.helper.add_key_path(entity.key, kind, str(uuid.uuid4()))
googledatastore.helper.add_properties(entity,
- {'content': six.text_type(content)})
+ {'content': unicode(content)})
return entity
entities = musicians | 'To Entity' >> beam.Map(to_entity)
diff --git a/sdks/python/apache_beam/examples/snippets/snippets_test.py
b/sdks/python/apache_beam/examples/snippets/snippets_test.py
index b05b6c4a220..b219609c037 100644
--- a/sdks/python/apache_beam/examples/snippets/snippets_test.py
+++ b/sdks/python/apache_beam/examples/snippets/snippets_test.py
@@ -17,6 +17,8 @@
#
"""Tests for all code snippets used in public docs."""
+from __future__ import absolute_import
+from __future__ import division
import glob
import gzip
@@ -25,6 +27,10 @@
import tempfile
import unittest
import uuid
+from builtins import map
+from builtins import object
+from builtins import range
+from builtins import zip
import mock
diff --git a/sdks/python/apache_beam/examples/streaming_wordcount.py
b/sdks/python/apache_beam/examples/streaming_wordcount.py
index 6ee50bea530..388f9e39b5b 100644
--- a/sdks/python/apache_beam/examples/streaming_wordcount.py
+++ b/sdks/python/apache_beam/examples/streaming_wordcount.py
@@ -23,8 +23,6 @@
import argparse
import logging
-import six
-
import apache_beam as beam
import apache_beam.transforms.window as window
from apache_beam.examples.wordcount import WordExtractingDoFn
@@ -32,6 +30,11 @@
from apache_beam.options.pipeline_options import SetupOptions
from apache_beam.options.pipeline_options import StandardOptions
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
def run(argv=None):
"""Build and run the pipeline."""
@@ -72,7 +75,7 @@ def count_ones(word_ones):
counts = (lines
| 'split' >> (beam.ParDo(WordExtractingDoFn())
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| beam.WindowInto(window.FixedWindows(15, 0))
| 'group' >> beam.GroupByKey()
diff --git a/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py
b/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py
index 30e438098b1..419e247e8ef 100644
--- a/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py
+++ b/sdks/python/apache_beam/examples/streaming_wordcount_debugging.py
@@ -38,8 +38,6 @@
import logging
import re
-import six
-
import apache_beam as beam
import apache_beam.transforms.window as window
from apache_beam.examples.wordcount import WordExtractingDoFn
@@ -50,6 +48,11 @@
from apache_beam.testing.util import equal_to_per_window
from apache_beam.transforms.core import ParDo
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class PrintFn(beam.DoFn):
"""A DoFn that prints label, element, its window, and its timstamp. """
@@ -119,7 +122,7 @@ def count_ones(word_ones):
| 'AddTimestampFn' >> beam.ParDo(AddTimestampFn())
| 'After AddTimestampFn' >> ParDo(PrintFn('After AddTimestampFn'))
| 'Split' >> (beam.ParDo(WordExtractingDoFn())
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'PairWithOne' >> beam.Map(lambda x: (x, 1))
| beam.WindowInto(window.FixedWindows(5, 0))
| 'GroupByKey' >> beam.GroupByKey()
diff --git a/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py
b/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py
index 5db1878f34f..3c0cfa93a2c 100644
--- a/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py
+++ b/sdks/python/apache_beam/examples/streaming_wordcount_it_test.py
@@ -17,9 +17,12 @@
"""End-to-end test for the streaming wordcount example."""
+from __future__ import absolute_import
+
import logging
import unittest
import uuid
+from builtins import range
from hamcrest.core.core.allof import all_of
from nose.plugins.attrib import attr
diff --git a/sdks/python/apache_beam/examples/user_score_it_test.py
b/sdks/python/apache_beam/examples/user_score_it_test.py
index 7cd59e91a81..1c754a92ff5 100644
--- a/sdks/python/apache_beam/examples/user_score_it_test.py
+++ b/sdks/python/apache_beam/examples/user_score_it_test.py
@@ -30,6 +30,8 @@
"""
+from __future__ import absolute_import
+
import logging
import unittest
import uuid
diff --git a/sdks/python/apache_beam/examples/windowed_wordcount.py
b/sdks/python/apache_beam/examples/windowed_wordcount.py
index 987b66040a7..b5c4fde7aa7 100644
--- a/sdks/python/apache_beam/examples/windowed_wordcount.py
+++ b/sdks/python/apache_beam/examples/windowed_wordcount.py
@@ -26,11 +26,14 @@
import argparse
import logging
-import six
-
import apache_beam as beam
import apache_beam.transforms.window as window
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
TABLE_SCHEMA = ('word:STRING, count:INTEGER, '
'window_start:TIMESTAMP, window_end:TIMESTAMP')
@@ -77,7 +80,7 @@ def count_ones(word_ones):
transformed = (lines
| 'Split' >> (beam.FlatMap(find_words)
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'PairWithOne' >> beam.Map(lambda x: (x, 1))
| beam.WindowInto(window.FixedWindows(2*60, 0))
| 'Group' >> beam.GroupByKey()
diff --git a/sdks/python/apache_beam/examples/wordcount.py
b/sdks/python/apache_beam/examples/wordcount.py
index a26ef8a9bc7..3ba3b334188 100644
--- a/sdks/python/apache_beam/examples/wordcount.py
+++ b/sdks/python/apache_beam/examples/wordcount.py
@@ -23,8 +23,6 @@
import logging
import re
-import six
-
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
@@ -33,6 +31,11 @@
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class WordExtractingDoFn(beam.DoFn):
"""Parse each line of input text into words."""
@@ -96,7 +99,7 @@ def count_ones(word_ones):
counts = (lines
| 'split' >> (beam.ParDo(WordExtractingDoFn())
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| 'group' >> beam.GroupByKey()
| 'count' >> beam.Map(count_ones))
diff --git a/sdks/python/apache_beam/examples/wordcount_debugging.py
b/sdks/python/apache_beam/examples/wordcount_debugging.py
index 9fdcade7a26..5d932d54ec6 100644
--- a/sdks/python/apache_beam/examples/wordcount_debugging.py
+++ b/sdks/python/apache_beam/examples/wordcount_debugging.py
@@ -45,8 +45,6 @@
import logging
import re
-import six
-
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
@@ -56,6 +54,11 @@
from apache_beam.testing.util import assert_that
from apache_beam.testing.util import equal_to
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class FilterTextFn(beam.DoFn):
"""A DoFn that filters for a specific key based on a regular expression."""
@@ -101,7 +104,7 @@ def count_ones(word_ones):
return (pcoll
| 'split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x))
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| 'group' >> beam.GroupByKey()
| 'count' >> beam.Map(count_ones))
diff --git a/sdks/python/apache_beam/examples/wordcount_debugging_test.py
b/sdks/python/apache_beam/examples/wordcount_debugging_test.py
index 92ee2402ad6..513b72426eb 100644
--- a/sdks/python/apache_beam/examples/wordcount_debugging_test.py
+++ b/sdks/python/apache_beam/examples/wordcount_debugging_test.py
@@ -17,6 +17,8 @@
"""Test for the debugging wordcount example."""
+from __future__ import absolute_import
+
import logging
import re
import tempfile
diff --git a/sdks/python/apache_beam/examples/wordcount_fnapi.py
b/sdks/python/apache_beam/examples/wordcount_fnapi.py
index dce24517b11..00964c9ea46 100644
--- a/sdks/python/apache_beam/examples/wordcount_fnapi.py
+++ b/sdks/python/apache_beam/examples/wordcount_fnapi.py
@@ -28,8 +28,6 @@
import logging
import re
-import six
-
import apache_beam as beam
from apache_beam.io import ReadFromText
# TODO(BEAM-2887): Enable after the issue is fixed.
@@ -40,6 +38,11 @@
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
class WordExtractingDoFn(beam.DoFn):
"""Parse each line of input text into words."""
@@ -104,7 +107,7 @@ def run(argv=None):
counts = (lines
| 'split' >> (beam.ParDo(WordExtractingDoFn())
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'pair_with_one' >> beam.Map(lambda x: (x, 1))
| 'group_and_sum' >> beam.CombinePerKey(sum))
diff --git a/sdks/python/apache_beam/examples/wordcount_it_test.py
b/sdks/python/apache_beam/examples/wordcount_it_test.py
index fe42a4fa5f0..4c262746e36 100644
--- a/sdks/python/apache_beam/examples/wordcount_it_test.py
+++ b/sdks/python/apache_beam/examples/wordcount_it_test.py
@@ -17,6 +17,8 @@
"""End-to-end test for the wordcount example."""
+from __future__ import absolute_import
+
import logging
import time
import unittest
diff --git a/sdks/python/apache_beam/examples/wordcount_minimal.py
b/sdks/python/apache_beam/examples/wordcount_minimal.py
index 34abdb78a0d..1fbca327964 100644
--- a/sdks/python/apache_beam/examples/wordcount_minimal.py
+++ b/sdks/python/apache_beam/examples/wordcount_minimal.py
@@ -50,14 +50,17 @@
import logging
import re
-import six
-
import apache_beam as beam
from apache_beam.io import ReadFromText
from apache_beam.io import WriteToText
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
+try:
+ unicode # pylint: disable=unicode-builtin
+except NameError:
+ unicode = str
+
def run(argv=None):
"""Main entry point; defines and runs the wordcount pipeline."""
@@ -103,7 +106,7 @@ def run(argv=None):
counts = (
lines
| 'Split' >> (beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x))
- .with_output_types(six.text_type))
+ .with_output_types(unicode))
| 'PairWithOne' >> beam.Map(lambda x: (x, 1))
| 'GroupAndSum' >> beam.CombinePerKey(sum))
diff --git a/sdks/python/apache_beam/examples/wordcount_minimal_test.py
b/sdks/python/apache_beam/examples/wordcount_minimal_test.py
index 5ee7b780398..24ece493e09 100644
--- a/sdks/python/apache_beam/examples/wordcount_minimal_test.py
+++ b/sdks/python/apache_beam/examples/wordcount_minimal_test.py
@@ -17,6 +17,8 @@
"""Test for the minimal wordcount example."""
+from __future__ import absolute_import
+
import collections
import logging
import re
@@ -52,7 +54,7 @@ def test_basics(self):
match = re.search(r'([a-z]+): ([0-9]+)', line)
if match is not None:
results.append((match.group(1), int(match.group(2))))
- self.assertEqual(sorted(results), sorted(expected_words.iteritems()))
+ self.assertEqual(sorted(results), sorted(expected_words.items()))
if __name__ == '__main__':
diff --git a/sdks/python/apache_beam/examples/wordcount_test.py
b/sdks/python/apache_beam/examples/wordcount_test.py
index 9834ba53111..58655dd3319 100644
--- a/sdks/python/apache_beam/examples/wordcount_test.py
+++ b/sdks/python/apache_beam/examples/wordcount_test.py
@@ -17,6 +17,8 @@
"""Test for the wordcount example."""
+from __future__ import absolute_import
+
import collections
import logging
import re
@@ -51,7 +53,7 @@ def test_basics(self):
match = re.search(r'([a-z]+): ([0-9]+)', line)
if match is not None:
results.append((match.group(1), int(match.group(2))))
- self.assertEqual(sorted(results), sorted(expected_words.iteritems()))
+ self.assertEqual(sorted(results), sorted(expected_words.items()))
if __name__ == '__main__':
diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini
index 14b6c8bad0d..c80cefd24cb 100644
--- a/sdks/python/tox.ini
+++ b/sdks/python/tox.ini
@@ -100,6 +100,7 @@ deps =
flake8==3.5.0
modules =
apache_beam/coders
+ apache_beam/examples
apache_beam/portability
apache_beam/internal
apache_beam/metrics
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 113899)
Time Spent: 2h 10m (was: 2h)
> Futurize and fix python 2 compatibility for examples subpackage
> ---------------------------------------------------------------
>
> Key: BEAM-3998
> URL: https://issues.apache.org/jira/browse/BEAM-3998
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Robbe
> Assignee: Matthias Feys
> Priority: Major
> Time Spent: 2h 10m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)