Skip to content

Commit 2ee4f70

Browse files
authored
Merge pull request #39 from awslabs/dev
List of constraints support
2 parents 6ee23cf + b846c54 commit 2ee4f70

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

pydeequ/checks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,20 @@ def __init__(self, spark_session: SparkSession, level: CheckLevel, description:
9898
getattr(self._check_java_class, 'apply$default$3')()
9999
)
100100
self.constraints = constraints if constraints else []
101-
for constraint in self.constraints:
102-
self.addConstraint(constraint)
101+
102+
def addConstraints(self, constraints: list):
103+
self.constraints.extend(constraints)
104+
for constraint in constraints:
105+
self._Check = constraint._Check
103106

104107
def addConstraint(self, constraint):
105108
"""
106109
Returns a new Check object with the given constraints added to the constraints list.
107110
:param Constraint constraint: new constraint to be added.
108111
:return: new Check object
109112
"""
110-
raise NotImplementedError("Private factory method for other check methods")
113+
self.constraints.append(constraint)
114+
self._Check = constraint._Check
111115

112116
def addFilterableContstraint(self, creationFunc):
113117
""" Adds a constraint that can subsequently be replaced with a filtered version

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
def setup_package():
77
setup(
88
name='pydeequ',
9-
version="0.1.5",
9+
version="0.1.7",
1010
author="PyDeequ Developers",
11-
author_email="cghyzel@amazon.com",
11+
author_email="calviwan@amazon.com",
1212
description="Python API for Deequ",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

tests/test_checks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ def tearDownClass(cls):
3131
cls.spark.sparkContext._gateway.shutdown_callback_server()
3232
cls.spark.stop()
3333

34+
def testCheckConstraints(self):
35+
check = Check(self.spark, CheckLevel.Warning, "test list constraints")
36+
check.addConstraints([check.isComplete('c'),
37+
check.isUnique('b')])
38+
check.addConstraint(check.hasSize(lambda x: x == 3.0))
39+
40+
result = VerificationSuite(self.spark).onData(self.df) \
41+
.addCheck(check) \
42+
.run()
43+
44+
result_df = VerificationResult.checkResultsAsDataFrame(self.spark, result)
45+
46+
check2 = Check(self.spark, CheckLevel.Warning, "test list constraints")
47+
48+
result2 = VerificationSuite(self.spark).onData(self.df) \
49+
.addCheck(check2.isComplete('c').isUnique('b').hasSize(lambda x: x == 3.0)) \
50+
.run()
51+
52+
result_df2 = VerificationResult.checkResultsAsDataFrame(self.spark, result2)
53+
54+
self.assertEqual(result_df.select('constraint').collect(), result_df2.select('constraint').collect())
55+
3456
def test_initializer(self):
3557
# TODO verify that it does more than run
3658
check = Check(self.spark, CheckLevel.Warning, "test initializer")

0 commit comments

Comments
 (0)