You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/06/13 18:46:00 UTC
[jira] [Work logged] (BEAM-4005) Futurize and fix python 2
compatibility for tools subpackage
[ https://issues.apache.org/jira/browse/BEAM-4005?focusedWorklogId=111605&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-111605 ]
ASF GitHub Bot logged work on BEAM-4005:
----------------------------------------
Author: ASF GitHub Bot
Created on: 13/Jun/18 18:45
Start Date: 13/Jun/18 18:45
Worklog Time Spent: 10m
Work Description: asfgit closed pull request #5343: [BEAM-4005] Futurize tools subpackage
URL: https://github.com/apache/beam/pull/5343
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/tools/__init__.py b/sdks/python/apache_beam/tools/__init__.py
index 7b7c3b39193..30ca5c31be0 100644
--- a/sdks/python/apache_beam/tools/__init__.py
+++ b/sdks/python/apache_beam/tools/__init__.py
@@ -19,3 +19,4 @@
For internal use only; no backwards-compatibility guarantees.
"""
+from __future__ import absolute_import
diff --git a/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py b/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py
index 3e301eb2072..1e0809f0c11 100644
--- a/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py
+++ b/sdks/python/apache_beam/tools/distribution_counter_microbenchmark.py
@@ -23,11 +23,14 @@
python -m apache_beam.tools.distribution_counter_microbenchmark
"""
+from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import random
import sys
import time
+from builtins import range
from apache_beam.tools import utils
@@ -44,7 +47,7 @@ def run_benchmark(num_runs=100, num_input=10000, seed=time.time()):
total_time = 0
random.seed(seed)
lower_bound = 0
- upper_bound = sys.maxint
+ upper_bound = sys.maxsize
inputs = generate_input_values(num_input, lower_bound, upper_bound)
from apache_beam.transforms import DataflowDistributionCounter
print("Number of runs:", num_runs)
@@ -57,8 +60,8 @@ def run_benchmark(num_runs=100, num_input=10000, seed=time.time()):
counter.add_inputs_for_test(inputs)
time_cost = time.time() - start
print("Run %d: Total time cost %g sec" % (i+1, time_cost))
- total_time += time_cost/num_input
- print("Per element update time cost:", total_time/num_runs)
+ total_time += time_cost // num_input
+ print("Per element update time cost:", total_time // num_runs)
if __name__ == '__main__':
diff --git a/sdks/python/apache_beam/tools/map_fn_microbenchmark.py b/sdks/python/apache_beam/tools/map_fn_microbenchmark.py
index 537b90935d3..e640c2ba960 100644
--- a/sdks/python/apache_beam/tools/map_fn_microbenchmark.py
+++ b/sdks/python/apache_beam/tools/map_fn_microbenchmark.py
@@ -30,9 +30,13 @@
python -m apache_beam.tools.map_fn_microbenchmark
"""
+from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import time
+from builtins import range
+from builtins import zip
import apache_beam as beam
from apache_beam.tools import utils
@@ -45,7 +49,7 @@ def run_benchmark(num_maps=100, num_runs=10, num_elements_step=1000):
num_elements = num_elements_step * run + 1
start = time.time()
with beam.Pipeline() as p:
- pc = p | beam.Create(range(num_elements))
+ pc = p | beam.Create(list(range(num_elements)))
for ix in range(num_maps):
pc = pc | 'Map%d' % ix >> beam.FlatMap(lambda x: (None,))
timings[num_elements] = time.time() - start
@@ -55,9 +59,9 @@ def run_benchmark(num_maps=100, num_runs=10, num_elements_step=1000):
print
# pylint: disable=unused-variable
gradient, intercept, r_value, p_value, std_err = stats.linregress(
- *zip(*timings.items()))
+ *list(zip(*list(timings.items()))))
print("Fixed cost ", intercept)
- print("Per-element ", gradient / num_maps)
+ print("Per-element ", gradient // num_maps)
print("R^2 ", r_value**2)
diff --git a/sdks/python/apache_beam/tools/sideinput_microbenchmark.py b/sdks/python/apache_beam/tools/sideinput_microbenchmark.py
index 15e1b9bf33a..7cfdb29e189 100644
--- a/sdks/python/apache_beam/tools/sideinput_microbenchmark.py
+++ b/sdks/python/apache_beam/tools/sideinput_microbenchmark.py
@@ -22,9 +22,12 @@
python -m apache_beam.tools.sideinput_microbenchmark
"""
+from __future__ import absolute_import
+from __future__ import division
from __future__ import print_function
import time
+from builtins import range
from apache_beam.runners.worker import opcounters
from apache_beam.runners.worker import sideinputs
@@ -64,9 +67,10 @@ def run_benchmark(num_runs=50, input_per_source=4000, num_sources=4):
print("Runtimes:", times)
- avg_runtime = sum(times)/len(times)
+ avg_runtime = sum(times) // len(times)
print("Average runtime:", avg_runtime)
- print("Time per element:", avg_runtime/(input_per_source * num_sources))
+ print("Time per element:", avg_runtime // (input_per_source *
+ num_sources))
if __name__ == '__main__':
diff --git a/sdks/python/apache_beam/tools/utils.py b/sdks/python/apache_beam/tools/utils.py
index d643195be18..f2a9c214ae4 100644
--- a/sdks/python/apache_beam/tools/utils.py
+++ b/sdks/python/apache_beam/tools/utils.py
@@ -17,6 +17,8 @@
"""Utility functions for all microbenchmarks."""
+from __future__ import absolute_import
+
import os
diff --git a/sdks/python/tox.ini b/sdks/python/tox.ini
index caa899de2db..6fc16cb7162 100644
--- a/sdks/python/tox.ini
+++ b/sdks/python/tox.ini
@@ -99,6 +99,7 @@ deps =
flake8==3.5.0
modules =
apache_beam/coders
+ apache_beam/tools
commands =
python --version
pip --version
----------------------------------------------------------------
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:
users@infra.apache.org
Issue Time Tracking
-------------------
Worklog Id: (was: 111605)
Time Spent: 1h (was: 50m)
> Futurize and fix python 2 compatibility for tools subpackage
> ------------------------------------------------------------
>
> Key: BEAM-4005
> URL: https://issues.apache.org/jira/browse/BEAM-4005
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Robbe
> Assignee: Matthias Feys
> Priority: Major
> Time Spent: 1h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)