Skip to content

Commit

Permalink
further fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingCat committed Mar 13, 2014
1 parent a40e8fb commit 810948d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions core/src/main/scala/org/apache/spark/rdd/RDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ abstract class RDD[T: ClassTag](
* Return a sampled subset of this RDD.
*/
def sample(withReplacement: Boolean, fraction: Double, seed: Int): RDD[T] = {
require(fraction >= 0 && fraction <= Double.MaxValue,
"Invalid fraction value: " + fraction)
require(fraction >= 0.0, "Invalid fraction value: " + fraction)
if (withReplacement) {
new PartitionwiseSampledRDD[T, T](this, new PoissonSampler[T](fraction), seed)
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ class RDDSuite extends FunSuite with SharedSparkContext {

test("takeSample") {
val data = sc.parallelize(1 to 100, 2)
val emptySet = data.filter(_ => false)
val emptySet = data.mapPartitions { iter => Iterator.empty }

val sample = emptySet.takeSample(false, 20, 1)
assert(sample.size === 0)
assert(sample.length === 0)
for (seed <- 1 to 5) {
val sample = data.takeSample(withReplacement=false, 20, seed)
assert(sample.size === 20) // Got exactly 20 elements
Expand Down

0 comments on commit 810948d

Please sign in to comment.