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

Added RatioOfSums analyzer and tests #1

Closed
wants to merge 8 commits into from
Closed
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
10 changes: 3 additions & 7 deletions src/main/scala/com/amazon/deequ/analyzers/RatioOfSums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ case class RatioOfSums(
result: Row,
offset: Int
): Option[RatioOfSumsState] = {
if (result.isNullAt(offset)) {
None
} else {
Some(
ifNoNullsIn(result, offset, howMany = 2) { _ =>
RatioOfSumsState(
result.getDouble(0),
result.getDouble(1)
result.getDouble(offset),
result.getDouble(offset + 1)
)
)
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/test/scala/com/amazon/deequ/analyzers/AnalyzerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,10 @@ class AnalyzerTests extends AnyWordSpec with Matchers with SparkContextSpec with
assert(analyzer.calculate(df).fullColumn.isDefined)
}

"compute ratio of sums correctly for numeric data" in withSparkSession { sparkSession =>
}

"Ratio of sums" should {
"compute ratio of sums correctly for numeric data" in withSparkSession { sparkSession =>
val df = getDfWithNumericValues(sparkSession)
RatioOfSums("att1", "att2").calculate(df).value shouldBe Success(21.0 / 18.0)
}
Expand All @@ -858,7 +861,7 @@ class AnalyzerTests extends AnyWordSpec with Matchers with SparkContextSpec with
assert(RatioOfSums("att1", "att2").calculate(df).value.isFailure)
}

"divide by zero" in withSparkSession { sparkSession =>
"fail if divide by zero" in withSparkSession { sparkSession =>
val df = getDfWithNumericValues(sparkSession)
val testVal = RatioOfSums("att1", "att2", Some("item IN ('1', '2')")).calculate(df)
assert(testVal.value.isSuccess)
Expand Down