Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-1251] Fix basestring, file(), reduce(), and xrange() for Python 3 #4804

Merged
merged 1 commit into from
Mar 8, 2018

Conversation

cclauss
Copy link

@cclauss cclauss commented Mar 6, 2018

basestring was removed in Python 3 because all str are Unicode so this PR:

  • Change instances of basestring to six.string_types
  • file() was removed from Python 3 in favor of open(). In one instance, this PR uses with open() as to ensure that files are properly closed and file handles are promptly garbage collected on all Python implementations.
  • reduce() was moved into functools in Python 3 so this PR replaces reduce() with functools.reduce().
  • xrange() was removed in Python 3 in favor of range() so this PR replaces xrange() with range().

R: @aaltay

DESCRIPTION HERE


Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand:
    • What the pull request does
    • Why it does it
    • How it does it
    • Why this approach
  • Each commit in the pull request should have a meaningful subject line and body.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@cclauss
Copy link
Author

cclauss commented Mar 6, 2018

R: @aaltay

@cclauss cclauss force-pushed the basestring-to-six.string_types branch 2 times, most recently from aa74f38 to 1bb620f Compare March 7, 2018 00:21
@@ -44,6 +44,7 @@
from apache_beam.transforms.window import TimestampCombiner
from apache_beam.transforms.window import TimestampedValue
from apache_beam.utils import windowed_value
from six.moves import xrange
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use range in this file instead? I only see one usage of xrange and it is for list size limited by length of pcollections that is going into a cogroupbykey. Assuming that it will not be a large number, I do not think we need to xrange there.

@@ -39,6 +39,7 @@
from apache_beam.testing.util import assert_that
from apache_beam.testing.util import equal_to
from apache_beam.utils.windowed_value import WindowedValue
from six.moves import reduce
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use functools.reduce instead? The reduce is used below in a snippet and we publish those on our website. The example using reduce directly will be broken for python 3 users (they do not see the imports, only the snippet). However if we replace the usage of reduce with functools.reduce it will be a complete snippet.

@cclauss cclauss force-pushed the basestring-to-six.string_types branch from 1bb620f to e35dc23 Compare March 8, 2018 06:22
@cclauss
Copy link
Author

cclauss commented Mar 8, 2018

Done.

@aaltay
Copy link
Member

aaltay commented Mar 8, 2018

LGTM, Thank you.

@aaltay aaltay merged commit cc57d93 into apache:master Mar 8, 2018
@cclauss cclauss deleted the basestring-to-six.string_types branch March 8, 2018 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants