python/pyspark/rdd.py
def takeSample(self, withReplacement, num, seed):
        """
        Return a fixed-size sampled subset of this RDD (currently requires numpy).

        >>> sc.parallelize(range(0, 10)).takeSample(True, 10, 1) #doctest: +SKIP
        [4, 2, 1, 8, 2, 7, 0, 4, 1, 4]
        """

        fraction = 0.0
        total = 0
        multiplier = 3.0
        initialCount = self.count()
        maxSelected = 0

        if (num < 0):
            raise ValueError

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

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

        if num > initialCount and not withReplacement:
            total = maxSelected
            fraction = multiplier * (maxSelected + 1) / initialCount
        else:
            fraction = multiplier * (num + 1) / initialCount
            total = num

        samples = self.sample(withReplacement, fraction, seed).collect()

        # If the first sample didn't turn out large enough, keep trying to take samples;
        # this shouldn't happen often because we use a big multiplier for their initial size.
        # See: scala/spark/RDD.scala
        while len(samples) < total:
            if seed > sys.maxint - 2:
                seed = -1
            seed += 1
            samples = self.sample(withReplacement, fraction, seed).collect()

        sampler = RDDSampler(withReplacement, fraction, seed+1)
        sampler.shuffle(samples)
        return samples[0:total]

        Return a fixed-size sampled subset of this RDD (currently requires numpy).

        >>> sc.parallelize(range(0, 10)).takeSample(True, 10, 1) #doctest: +SKIP
        [4, 2, 1, 8, 2, 7, 0, 4, 1, 4]
        
Return a fixed-size sampled subset of this RDD (currently requires numpy).
Return a fixed - size sampled subset of this RDD ( currently requires numpy ) .
def takeSample(self, withReplacement, num, seed):
        fraction = 0.0
        total = 0
        multiplier = 3.0
        initialCount = self.count()
        maxSelected = 0
        if (num < 0):
            raise ValueError
        if (initialCount == 0):
            return list()
        if initialCount > sys.maxint - 1:
            maxSelected = sys.maxint - 1
        else:
            maxSelected = initialCount
        if num > initialCount and not withReplacement:
            total = maxSelected
            fraction = multiplier * (maxSelected + 1) / initialCount
        else:
            fraction = multiplier * (num + 1) / initialCount
            total = num
        samples = self.sample(withReplacement, fraction, seed).collect()
        while len(samples) < total:
            if seed > sys.maxint - 2:
                seed = -1
            seed += 1
            samples = self.sample(withReplacement, fraction, seed).collect()
        sampler = RDDSampler(withReplacement, fraction, seed+1)
        sampler.shuffle(samples)
        return samples[0:total]
def takeSample ( self , withReplacement , num , seed ) : fraction = 0.0 total = 0 multiplier = 3.0 initialCount = self . count ( ) maxSelected = 0 if ( num < 0 ) : raise ValueError if ( initialCount == 0 ) : return list ( ) if initialCount > sys . maxint - 1 : maxSelected = sys . maxint - 1 else : maxSelected = initialCount if num > initialCount and not withReplacement : total = maxSelected fraction = multiplier * ( maxSelected + 1 ) / initialCount else : fraction = multiplier * ( num + 1 ) / initialCount total = num samples = self . sample ( withReplacement , fraction , seed ) . collect ( ) while len ( samples ) < total : if seed > sys . maxint - 2 : seed = - 1 seed += 1 samples = self . sample ( withReplacement , fraction , seed ) . collect ( ) sampler = RDDSampler ( withReplacement , fraction , seed + 1 ) sampler . shuffle ( samples ) return samples [ 0 : total ]
Return a fixed-size sampled subset of this RDD (currently requires numpy).
Return a fixed - size sampled subset of this RDD ( currently requires numpy ) .
"""
        Return a fixed-size sampled subset of this RDD (currently requires numpy).

        >>> sc.parallelize(range(0, 10)).takeSample(True, 10, 1) #doctest: +SKIP
        [4, 2, 1, 8, 2, 7, 0, 4, 1, 4]
        """ # If the first sample didn't turn out large enough, keep trying to take samples; # this shouldn't happen often because we use a big multiplier for their initial size. # See: scala/spark/RDD.scala
self
withReplacement
num
seed