Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check array length + clues + fix fill geo location vectorizer values #132

Merged
merged 3 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ final class GeolocationVectorizerModel private[op]
def transformFn: Seq[Geolocation] => OPVector = row => {
val replaced =
if (!trackNulls) {
row.zip(fillValues).flatMap { case (r, m) => if (r.isEmpty) m else r.value }
row.zip(fillValues).flatMap { case (r, m) =>
val meanToUse: Seq[Double] = if (m.isEmpty) RepresentationOfEmpty else m
if (r.isEmpty) meanToUse else r.value
}
}
else {
row.zip(fillValues).flatMap { case (r, m) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ import org.scalatest.{Assertion, Matchers}

trait AttributeAsserts {
self: Matchers =>

/**
* Assert if attributes are nominal or not
*
* @param schema
* @param schema field schema with attributes attached
* @param expectedNominal Expected array of booleans. True if the field is nominal, false if not.
* @param output the output OPVector associated with the column
*/
final def assertNominal(schema: StructField, expectedNominal: Array[Boolean], output: Array[OPVector]): Assertion = {
val attributes = AttributeGroup.fromStructField(schema).attributes
for {
x <- output
(x, i) <- output.zipWithIndex
_ = withClue(s"Output vector $i and expectedNominal arrays are not of the same length:") {
x.value.size shouldBe expectedNominal.length
}
(value, nominal) <- x.value.toArray.zip(expectedNominal)
} if (nominal) value should (be (0.0) or be (1.0))
attributes.map(_.map(_.isNominal).toSeq) shouldBe Some(expectedNominal.toSeq)
} if (nominal) value should (be(0.0) or be(1.0))

val attributes = AttributeGroup.fromStructField(schema).attributes
withClue("Field attributes were not set or not as expected:") {
attributes.map(_.map(_.isNominal).toSeq) shouldBe Some(expectedNominal.toSeq)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ case object GeolocationMidpoint

trait GeolocationFunctions {

val Zero: Array[Double] = Array.fill[Double](4)(0.0)
val Zero: Array[Double] = new Array[Double](4)

def isNone(data: Array[Double]): Boolean = data(3) == 0
def isNone(data: Array[Double]): Boolean = data(3) == 0.0

/**
* Prepare method to be used in the MonoidAggregator for Geolocation objects
Expand All @@ -93,7 +93,7 @@ trait GeolocationFunctions {
if (input.isEmpty) Zero
else {
val g = input.toGeoPoint
val d = input.accuracy.rangeInUnits / 2
val d = input.accuracy.rangeInUnits / 2.0
Array[Double](
g.x, g.y, g.z,
1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ object Geolocation {
private[types] def geolocationData(
lat: Double,
lon: Double,
accuracy: GeolocationAccuracy): Seq[Double] =
geolocationData(lat, lon, accuracy.value)
accuracy: GeolocationAccuracy
): Seq[Double] = geolocationData(lat, lon, accuracy.value)

private[types] def geolocationData(
lat: Double,
Expand Down