Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/complete/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
1 change: 1 addition & 0 deletions sdks/python/apache_beam/examples/complete/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the autocomplete example."""

from __future__ import absolute_import

import unittest

import apache_beam as beam
Expand Down
3 changes: 3 additions & 0 deletions sdks/python/apache_beam/examples/complete/estimate_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/complete/estimate_pi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the estimate_pi example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/complete/game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/examples/complete/game/game_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the game_stats example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the user_score example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the leader_board example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
3 changes: 2 additions & 1 deletion sdks/python/apache_beam/examples/complete/game/user_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"""

from __future__ import absolute_import
from __future__ import division

import argparse
import csv
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the user_score example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the juliaset example."""

from __future__ import absolute_import

import logging
import os
import re
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

"""

from __future__ import absolute_import

import logging

from apache_beam.examples.complete.juliaset.juliaset import juliaset
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/complete/juliaset/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sdks/python/apache_beam/examples/complete/tfidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

from __future__ import absolute_import
from __future__ import division

import argparse
import glob
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/complete/tfidf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the TF-IDF example."""

from __future__ import absolute_import

import logging
import os
import re
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the top wikipedia sessions example."""

from __future__ import absolute_import

import json
import unittest

Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/cookbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import absolute_import
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the BigQuery side input example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the BigQuery tornadoes example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
1 change: 1 addition & 0 deletions sdks/python/apache_beam/examples/cookbook/coders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/cookbook/coders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the coders example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/cookbook/combiners_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
checked directly on the last PCollection produced.
"""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Tests for the various custom Count implementation examples."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
11 changes: 8 additions & 3 deletions sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/examples/cookbook/filters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Test for the filters example."""

from __future__ import absolute_import

import logging
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import argparse
import logging
import sys
from builtins import object

import apache_beam as beam
from apache_beam import coders
Expand Down
Loading