Skip to content

Commit

Permalink
fix the same problem in PySpark
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingCat committed Mar 14, 2014
1 parent 36db06b commit fef57d4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/pyspark/rdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def sample(self, withReplacement, fraction, seed):
>>> sc.parallelize(range(0, 100)).sample(False, 0.1, 2).collect() #doctest: +SKIP
[2, 3, 20, 21, 24, 41, 42, 66, 67, 89, 90, 98]
"""
assert fraction >= 0.0, "Invalid fraction value: %s" % fraction
return self.mapPartitionsWithIndex(RDDSampler(withReplacement, fraction, seed).func, True)

# this is ported from scala/spark/RDD.scala
Expand All @@ -288,6 +289,9 @@ def takeSample(self, withReplacement, num, seed):
if (num < 0):
raise ValueError

if (initialCount == 0):
return list()

if initialCount > sys.maxint - 1:
maxSelected = sys.maxint - 1
else:
Expand Down

0 comments on commit fef57d4

Please sign in to comment.