-
Notifications
You must be signed in to change notification settings - Fork 325
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
Remove handling_strategy parameter #843
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7e36919
changing logic for handling constraints
amontanez24 e2af95a
fixing a lot of tests
amontanez24 4718be5
removing handling_strategy attribute
amontanez24 94445ca
removing handling_strategy from docs and code
amontanez24 a6163eb
fixing tests, docs and tutorials
amontanez24 9744cc3
adding unit tests
amontanez24 82f8380
only calling reverse_transform if custom constraint
amontanez24 6539c67
ignoring sre_parse during isort
78bd7cd
pr comments
90b6003
raising all errors except missing column erros
amontanez24 1ff251b
adding integration test and tracking if reverse transform should use …
amontanez24 7f3f74b
refactoring how constraint transforms happen
amontanez24 e163b7d
adding unit tests
amontanez24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,6 +411,14 @@ def _get_transformers(self, dtypes): | |
|
||
return transformers | ||
|
||
@staticmethod | ||
def _warn_of_missing_columns(constraint, error): | ||
warnings.warn( | ||
f'{constraint.__class__.__name__} cannot be transformed because columns: ' | ||
f'{error.missing_columns} are not found. Using the reject sampling approach ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'instead.' | ||
) | ||
|
||
def _fit_transform_constraints(self, data): | ||
errors = [] | ||
# Fit and validate all constraints first because `transform` might change columns | ||
|
@@ -424,6 +432,8 @@ def _fit_transform_constraints(self, data): | |
for constraint in self._constraints: | ||
try: | ||
data = constraint.transform(data) | ||
except MissingConstraintColumnError as e: | ||
Table._warn_of_missing_columns(constraint, e) | ||
except Exception as e: | ||
errors.append(e) | ||
|
||
|
@@ -581,11 +591,7 @@ def _transform_constraints(self, data): | |
try: | ||
data = constraint.transform(data) | ||
except MissingConstraintColumnError as e: | ||
warnings.warn( | ||
f'{constraint.__class__.__name__} cannot be transformed because columns: ' | ||
f'{e.missing_columns} are not found. Using the reject sampling approach ' | ||
'instead.' | ||
) | ||
Table._warn_of_missing_columns(constraint, e) | ||
indices_to_drop = data.columns.isin(constraint.constraint_columns) | ||
columns_to_drop = data.columns.where(indices_to_drop).dropna() | ||
data = data.drop(columns_to_drop, axis=1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just copy paste the function logic here, instead of creating it separetely. The docstrings already describe that method either way, and it doesn't really have any test cases.