-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23698][Python] Resolve undefined names in Python 3 #20838
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
Changes from all commits
3e645a7
a74bb53
561ec8a
54d6563
4e74e68
f41bc31
73a4fd2
afd508e
5b3658c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,9 @@ | |
| from pyspark import since, _NoValue | ||
| from pyspark.rdd import ignore_unicode_prefix | ||
|
|
||
| if sys.version_info[0] >= 3: | ||
| basestring = str | ||
|
|
||
|
|
||
| class RuntimeConfig(object): | ||
| """User-facing configuration API, accessible through `SparkSession.conf`. | ||
|
|
@@ -59,7 +62,7 @@ def unset(self, key): | |
|
|
||
| def _checkType(self, obj, identifier): | ||
| """Assert that an object is of type str.""" | ||
| if not isinstance(obj, str) and not isinstance(obj, unicode): | ||
| if not isinstance(obj, basestring): | ||
|
||
| raise TypeError("expected %s '%s' to be a string (was '%s')" % | ||
| (identifier, obj, type(obj).__name__)) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ | |
|
|
||
| if sys.version < "3": | ||
| from itertools import imap as map, ifilter as filter | ||
| else: | ||
| long = int | ||
|
||
|
|
||
| from py4j.protocol import Py4JJavaError | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,7 +179,7 @@ def func(dstream): | |
| self._test_func(input, func, expected) | ||
|
|
||
| def test_flatMap(self): | ||
| """Basic operation test for DStream.faltMap.""" | ||
| """Basic operation test for DStream.flatMap.""" | ||
| input = [range(1, 5), range(5, 9), range(9, 13)] | ||
|
|
||
| def func(dstream): | ||
|
|
@@ -206,6 +206,38 @@ def func(dstream): | |
| expected = [[len(x)] for x in input] | ||
| self._test_func(input, func, expected) | ||
|
|
||
| def test_slice(self): | ||
| """Basic operation test for DStream.slice.""" | ||
| import datetime as dt | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove the import here since it is at the top already
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, not your doing but I noticed this spelling error on ln 183 "DStream.faltMap" should be "DStream.flatMap", would you mind changing that while we are here? |
||
| self.ssc = StreamingContext(self.sc, 1.0) | ||
| self.ssc.remember(4.0) | ||
| input = [[1], [2], [3], [4]] | ||
| stream = self.ssc.queueStream([self.sc.parallelize(d, 1) for d in input]) | ||
|
|
||
| time_vals = [] | ||
|
|
||
| def get_times(t, rdd): | ||
| if rdd and len(time_vals) < len(input): | ||
| time_vals.append(t) | ||
|
|
||
| stream.foreachRDD(get_times) | ||
|
|
||
| self.ssc.start() | ||
| self.wait_for(time_vals, 4) | ||
| begin_time = time_vals[0] | ||
|
|
||
| def get_sliced(begin_delta, end_delta): | ||
| begin = begin_time + dt.timedelta(seconds=begin_delta) | ||
| end = begin_time + dt.timedelta(seconds=end_delta) | ||
| rdds = stream.slice(begin, end) | ||
| result_list = [rdd.collect() for rdd in rdds] | ||
| return [r for result in result_list for r in result] | ||
|
|
||
| self.assertEqual(set([1]), set(get_sliced(0, 0))) | ||
| self.assertEqual(set([2, 3]), set(get_sliced(1, 2))) | ||
| self.assertEqual(set([2, 3, 4]), set(get_sliced(1, 4))) | ||
| self.assertEqual(set([1, 2, 3, 4]), set(get_sliced(0, 4))) | ||
|
|
||
| def test_reduce(self): | ||
| """Basic operation test for DStream.reduce.""" | ||
| input = [range(1, 5), range(5, 9), range(9, 13)] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you just put this above:
and then just do?
I don't think you need to specify "UTF-8" because either way it will be a unicode object, but I'm not too sure how this conversion is supposed to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BryanCutler I think we do need to specify it because it won't be unicode type in Python 2, we get these from run_cmd which call's Popen communicate which returns a regular string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... My other worry in Py2 would be if sys.setdefaultencoding() was set to somthing other that utf-8. That method was also thankfully dropped in Py3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that we are first casting
authorthis to unicode already withunicode(author)and it doesn't really matter if it is "UTF-8" or not because we then immediately decode it into ASCII withunidecode, which can handle it even it it wasn't "UTF-8", so the end result should be the same I believe. It was just to clean up a little, so not a big deal either way. The way it is now replicates the old behavior, so it's probably safer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's agree to leave this as is in this PR. EOL of Python 2 in 500 daze away so safe is better.