Skip to content

Commit fd3fd4b

Browse files
committed
fixed error, updated test
1 parent 82cde0e commit fd3fd4b

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

core/src/main/scala/org/apache/spark/api/java/JavaRDDLike.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ trait JavaRDDLike[T, This <: JavaRDDLike[T, This]] extends Serializable {
484484
* @return the maximum of the RDD
485485
* */
486486
def max(comp: Comparator[T]): T = {
487-
import scala.collection.JavaConversions._
488487
rdd.max()(Ordering.comparatorToOrdering(comp))
489488
}
490489

@@ -495,7 +494,6 @@ trait JavaRDDLike[T, This <: JavaRDDLike[T, This]] extends Serializable {
495494
* @return the minimum of the RDD
496495
* */
497496
def min(comp: Comparator[T]): T = {
498-
import scala.collection.JavaConversions._
499497
rdd.min()(Ordering.comparatorToOrdering(comp))
500498
}
501499

core/src/main/scala/org/apache/spark/util/StatCounter.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
2929
private var n: Long = 0 // Running count of our values
3030
private var mu: Double = 0 // Running mean of our values
3131
private var m2: Double = 0 // Running variance numerator (sum of (x - mean)^2)
32-
private var max_v: Double = Double.NegativeInfinity // Running max of our values
33-
private var min_v: Double = Double.PositiveInfinity // Running min of our values
32+
private var maxValue: Double = Double.NegativeInfinity // Running max of our values
33+
private var minValue: Double = Double.PositiveInfinity // Running min of our values
3434

3535
merge(values)
3636

@@ -43,8 +43,8 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
4343
n += 1
4444
mu += delta / n
4545
m2 += delta * (value - mu)
46-
max_v = math.max(max_v, value)
47-
min_v = math.min(min_v, value)
46+
maxValue = math.max(maxValue, value)
47+
minValue = math.min(minValue, value)
4848
this
4949
}
5050

@@ -63,8 +63,8 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
6363
mu = other.mu
6464
m2 = other.m2
6565
n = other.n
66-
max_v = other.max_v
67-
min_v = other.min_v
66+
maxValue = other.maxValue
67+
minValue = other.minValue
6868
} else if (other.n != 0) {
6969
val delta = other.mu - mu
7070
if (other.n * 10 < n) {
@@ -76,8 +76,8 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
7676
}
7777
m2 += other.m2 + (delta * delta * n * other.n) / (n + other.n)
7878
n += other.n
79-
max_v = math.max(max_v, other.max_v)
80-
min_v = math.min(min_v, other.min_v)
79+
maxValue = math.max(maxValue, other.maxValue)
80+
minValue = math.min(minValue, other.minValue)
8181
}
8282
this
8383
}
@@ -89,8 +89,8 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
8989
other.n = n
9090
other.mu = mu
9191
other.m2 = m2
92-
other.max_v = max_v
93-
other.min_v = min_v
92+
other.maxValue = maxValue
93+
other.minValue = minValue
9494
other
9595
}
9696

@@ -100,9 +100,9 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
100100

101101
def sum: Double = n * mu
102102

103-
def max: Double = max_v
103+
def max: Double = maxValue
104104

105-
def min: Double = min_v
105+
def min: Double = minValue
106106

107107
/** Return the variance of the values. */
108108
def variance: Double = {
@@ -135,7 +135,7 @@ class StatCounter(values: TraversableOnce[Double]) extends Serializable {
135135
def sampleStdev: Double = math.sqrt(sampleVariance)
136136

137137
override def toString: String = {
138-
"(count: %d, mean: %f, stdev: %f, max: %f, min: $f)".format(count, mean, stdev, max, min)
138+
"(count: %d, mean: %f, stdev: %f, max: %f, min: %f)".format(count, mean, stdev, max, min)
139139
}
140140
}
141141

core/src/test/scala/org/apache/spark/PartitioningSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class PartitioningSuite extends FunSuite with SharedSparkContext with PrivateMet
172172
assert(abs(1.0 - rdd.variance) < 0.01)
173173
assert(abs(1.0 - rdd.stdev) < 0.01)
174174
assert(stats.max === 4.0)
175-
assert(stats.min === -1.0)
175+
assert(stats.min === 2.0)
176176

177177
// Add other tests here for classes that should be able to handle empty partitions correctly
178178
}

python/pyspark/statcounter.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def __init__(self, values=[]):
2626
self.n = 0L # Running count of our values
2727
self.mu = 0.0 # Running mean of our values
2828
self.m2 = 0.0 # Running variance numerator (sum of (x - mean)^2)
29-
self.max_v = float("-inf")
30-
self.min_v = float("inf")
29+
self.maxValue = float("-inf")
30+
self.minValue = float("inf")
3131

3232
for v in values:
3333
self.merge(v)
@@ -38,10 +38,10 @@ def merge(self, value):
3838
self.n += 1
3939
self.mu += delta / self.n
4040
self.m2 += delta * (value - self.mu)
41-
if self.max_v < value:
42-
self.max_v = value
43-
if self.min_v > value:
44-
self.min_v = value
41+
if self.maxValue < value:
42+
self.maxValue = value
43+
if self.minValue > value:
44+
self.minValue = value
4545

4646
return self
4747

@@ -57,8 +57,8 @@ def mergeStats(self, other):
5757
self.mu = other.mu
5858
self.m2 = other.m2
5959
self.n = other.n
60-
self.max_v = other.max_v
61-
self.min_v = other.min_v
60+
self.maxValue = other.maxValue
61+
self.minValue = other.minValue
6262

6363
elif other.n != 0:
6464
delta = other.mu - self.mu
@@ -69,8 +69,8 @@ def mergeStats(self, other):
6969
else:
7070
self.mu = (self.mu * self.n + other.mu * other.n) / (self.n + other.n)
7171

72-
self.max_v = max(self.max_v, other.max_v)
73-
self.min_v = min(self.min_v, other.min_v)
72+
self.maxValue = max(self.maxValue, other.maxValue)
73+
self.minValue = min(self.minValue, other.minValue)
7474

7575
self.m2 += other.m2 + (delta * delta * self.n * other.n) / (self.n + other.n)
7676
self.n += other.n
@@ -90,10 +90,10 @@ def sum(self):
9090
return self.n * self.mu
9191

9292
def min(self):
93-
return self.min_v
93+
return self.minValue
9494

9595
def max(self):
96-
return self.max_v
96+
return self.maxValue
9797

9898
# Return the variance of the values.
9999
def variance(self):

0 commit comments

Comments
 (0)