Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-8116

sc.range() doesn't match python range()

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4.0, 1.4.1
    • Fix Version/s: 1.4.1, 1.5.0
    • Component/s: PySpark
    • Labels:
    • Target Version/s:

      Description

      Python's built-in range() and xrange() functions can take 1, 2, or 3 arguments. Ranges with just 1 argument are probably used the most frequently, e.g.:
      for i in range(len(myList)): ...

      However, in pyspark, the SparkContext range() method throws an error when called with a single argument, due to the way its arguments get passed into python's range function.

      There's no good reason that I can think of not to support the same syntax as the built-in function. To fix this, we can set the default of the sc.range() method's `stop` argument to None, and then inside the method, if it is None, replace `stop` with `start` and set `start` to 0, which is what the c implementation of range() does:
      https://github.com/python/cpython/blob/master/Objects/rangeobject.c#L87

        Attachments

          Activity

            People

            • Assignee:
              belisarius222 Ted Blackman
              Reporter:
              belisarius222 Ted Blackman
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: