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

Unit test based on titanic dataset for column profiling. #191

Merged
merged 4 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
51 changes: 51 additions & 0 deletions src/test/scala/com/amazon/deequ/profiles/ColumnProfilerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,55 @@ class ColumnProfilerTest extends WordSpec with Matchers with SparkContextSpec
}
}

"return correct profile for the Titanic dataset" in withSparkSession { session =>
val data = session.read.format("csv")
klangner marked this conversation as resolved.
Show resolved Hide resolved
.option("inferSchema", "true")
.option("header", "true")
.load("test-data/titanic.csv")

val columnProfiles = ColumnProfiler.profile(data)

val expectedProfiles = List(
StandardColumnProfile(
"PassengerId",
1.0,
891,
DataTypeInstances.Integral,
false,
Map(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Map.empty instead of Map() here and in the subsequent calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

None),
StandardColumnProfile("Survived", 1.0, 2, DataTypeInstances.Integral, false, Map(), None),
StandardColumnProfile("Pclass", 1.0, 3, DataTypeInstances.Integral, false, Map(), None),
StandardColumnProfile("Name", 1.0, 0, DataTypeInstances.String, true, Map(), None),
StandardColumnProfile("Sex", 1.0, 2, DataTypeInstances.String, true, Map(), None),
StandardColumnProfile("Ticket", 1.0, 681, DataTypeInstances.String, true, Map(), None),
StandardColumnProfile("Fare", 1.0, 0, DataTypeInstances.Fractional, false, Map(), None),
StandardColumnProfile("Cabin", 0.22, 0, DataTypeInstances.String, true, Map(), None)
)

assertSameColumnProfiles(columnProfiles.profiles, expectedProfiles)

}

private[this] def assertSameColumnProfiles(
actualProfiles: Map[String, ColumnProfile],
expectedProfiles: List[ColumnProfile])
: Unit = {

expectedProfiles.foreach { expected =>
val actual = actualProfiles(expected.column)
val msg = s"""(Column "${expected.column}"")"""
assert(actual.dataType == expected.dataType, msg)
assert(actual.completeness >= expected.completeness, msg)
assert(actual.isDataTypeInferred == expected.isDataTypeInferred, msg)
if(expected.approximateNumDistinctValues > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

val upperBound = 1.1 * expected.approximateNumDistinctValues
val lowerBound = 0.9 * expected.approximateNumDistinctValues
assert(
actual.approximateNumDistinctValues <= upperBound &&
actual.approximateNumDistinctValues >= lowerBound,
msg)
}
}
}
}
3 changes: 3 additions & 0 deletions test-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dataset used for testing

* [titanic.csv](https://www.kaggle.com/c/titanic/data)
Loading