Repository: spark Updated Branches: refs/heads/branch-1.4 3ba6fc515 -> f02af7c8f
[SPARK-8116][PYSPARK] Allow sc.range() to take a single argument. Author: Ted Blackman <ted.black...@gmail.com> Closes #6656 from belisarius222/branch-1.4 and squashes the following commits: 747cbc2 [Ted Blackman] [SPARK-8116][PYSPARK] Allow sc.range() to take a single argument. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f02af7c8 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f02af7c8 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f02af7c8 Branch: refs/heads/branch-1.4 Commit: f02af7c8f7f43e4cfe3c412d2b5ea4128669ce22 Parents: 3ba6fc5 Author: Ted Blackman <ted.black...@gmail.com> Authored: Thu Jun 4 22:21:11 2015 -0700 Committer: Reynold Xin <r...@databricks.com> Committed: Thu Jun 4 22:21:11 2015 -0700 ---------------------------------------------------------------------- python/pyspark/context.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/f02af7c8/python/pyspark/context.py ---------------------------------------------------------------------- diff --git a/python/pyspark/context.py b/python/pyspark/context.py index aeb7ad4..44d90f1 100644 --- a/python/pyspark/context.py +++ b/python/pyspark/context.py @@ -324,10 +324,12 @@ class SparkContext(object): with SparkContext._lock: SparkContext._active_spark_context = None - def range(self, start, end, step=1, numSlices=None): + def range(self, start, end=None, step=1, numSlices=None): """ Create a new RDD of int containing elements from `start` to `end` - (exclusive), increased by `step` every element. + (exclusive), increased by `step` every element. Can be called the same + way as python's built-in range() function. If called with a single argument, + the argument is interpreted as `end`, and `start` is set to 0. :param start: the start value :param end: the end value (exclusive) @@ -335,9 +337,17 @@ class SparkContext(object): :param numSlices: the number of partitions of the new RDD :return: An RDD of int + >>> sc.range(5).collect() + [0, 1, 2, 3, 4] + >>> sc.range(2, 4).collect() + [2, 3] >>> sc.range(1, 7, 2).collect() [1, 3, 5] """ + if end is None: + end = start + start = 0 + return self.parallelize(xrange(start, end, step), numSlices) def parallelize(self, c, numSlices=None): --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org