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

Add create_custom_constraint method #848

Merged
merged 42 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7e36919
changing logic for handling constraints
amontanez24 Jun 10, 2022
e2af95a
fixing a lot of tests
amontanez24 Jun 11, 2022
4718be5
removing handling_strategy attribute
amontanez24 Jun 13, 2022
94445ca
removing handling_strategy from docs and code
amontanez24 Jun 13, 2022
a6163eb
fixing tests, docs and tutorials
amontanez24 Jun 14, 2022
9744cc3
adding unit tests
amontanez24 Jun 14, 2022
82f8380
only calling reverse_transform if custom constraint
amontanez24 Jun 17, 2022
6539c67
ignoring sre_parse during isort
Jun 22, 2022
78bd7cd
pr comments
Jun 22, 2022
90b6003
raising all errors except missing column erros
amontanez24 Jun 23, 2022
1ff251b
adding integration test and tracking if reverse transform should use …
amontanez24 Jun 23, 2022
7f3f74b
refactoring how constraint transforms happen
amontanez24 Jun 27, 2022
e163b7d
adding unit tests
amontanez24 Jun 27, 2022
7ac6c5e
Creates the custom constraint method
fealho Jun 22, 2022
82e4f1c
Add tests cases
fealho Jun 22, 2022
65cba76
Fix lint
fealho Jun 22, 2022
8fc1577
Finish unit tests
fealho Jun 22, 2022
35e6113
Add integration test + fix docstrings
fealho Jun 18, 2022
a35d7af
Fix lint
fealho Jun 18, 2022
73c43eb
Fix rebase issues
fealho Jun 22, 2022
3029f2b
Move lambda functions inside methods
fealho Jun 22, 2022
d3f9ca5
Working version using globals
fealho Jun 22, 2022
a1d9799
.
fealho Jun 22, 2022
a60cce9
Remove from_dict
fealho Jun 22, 2022
169ea40
Minor change
fealho Jun 23, 2022
1cdda5c
Remove all references to Constraint.from_dict
fealho Jun 23, 2022
d4a8398
Merge branch 'master' into issue-836-custom-constraint
fealho Jun 29, 2022
314bc75
Remove double __init__
fealho Jun 29, 2022
11ff23b
Squashed commit of the following:
fealho Jun 29, 2022
162431c
Merge branch 'master' into issue-836-custom-constraint
fealho Jun 29, 2022
9ad91cc
Updating the handling constraint documentation
Jun 22, 2022
c1fd7ef
fixing bugs in docs
Jun 23, 2022
b705c8b
loading constraints from dict if necessary
amontanez24 Jun 29, 2022
2c2df76
adding collapse for faq and fixing bugs
amontanez24 Jun 29, 2022
b2e6337
Change error handling for transform
fealho Jun 30, 2022
273e80b
fixing grammar error
amontanez24 Jun 30, 2022
4caedbc
Add from_dict back
fealho Jun 30, 2022
8469200
Fix lint
fealho Jun 30, 2022
4dbaa94
Add test case
fealho Jun 30, 2022
ba8632d
Merge branch 'update-handling-constraints-doc' into issue-836-custom-…
fealho Jun 30, 2022
83c6b3a
Merge branch 'master' into issue-836-custom-constraint
fealho Jun 30, 2022
6ed7a81
Updtae integration test
fealho Jun 30, 2022
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
1 change: 1 addition & 0 deletions sdv/constraints/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CustomConstraint(Constraint):
def __init__(self, column_names, **kwargs):
self.column_names = column_names
self.kwargs = kwargs
self.constraint_columns = tuple(column_names)

def is_valid(self, data):
"""Check whether the column values are valid.
Expand Down
13 changes: 12 additions & 1 deletion tests/integration/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
FixedCombinations, Inequality, Negative, OneHotEncoding, Positive, Range, ScalarInequality,
ScalarRange, Unique)
from sdv.constraints.errors import MultipleConstraintsErrors
from sdv.constraints.tabular import create_custom_constraint
from sdv.demo import load_tabular_demo
from sdv.tabular import GaussianCopula

Expand Down Expand Up @@ -50,7 +51,8 @@ def test_failing_constraints():
'g': [1, 0, 1, 0, 0, 1, 0],
'h': [1, 1, 1, 0, 0, 10, 0],
'i': [1, 1, 1, 1, 1, 1, 1],
'j': [2, 3, 4, 5, 6, 7, 5.5]
'j': [2, 3, 4, 5, 6, 7, 5.5],
'k': [1, -1, 2, -2, 3, -3, 5]
})

constraints = [
Expand All @@ -62,6 +64,9 @@ def test_failing_constraints():
ScalarInequality('j', '>=', 5.5),
Range('a', 'b', 'c'),
ScalarRange('a', 0, 0),
create_custom_constraint(
lambda _, x: pd.Series([True if x_i > 0 else False for x_i in x['k']])
)('k')
fealho marked this conversation as resolved.
Show resolved Hide resolved
]
gc = GaussianCopula(constraints=constraints)

Expand Down Expand Up @@ -130,6 +135,12 @@ def test_failing_constraints():
'\n3 0'
'\n4 0'
'\n+2 more'
'\n'
"\nData is not valid for the 'CustomConstraint' constraint:"
'\n k'
'\n1 -1'
'\n3 -2'
'\n5 -3'
)

with pytest.raises(MultipleConstraintsErrors, match=err_msg):
Expand Down