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

Allow me to create a custom constraint class and use it in the same file #1205

Closed
npatki opened this issue Jan 27, 2023 · 0 comments
Closed
Assignees
Labels
feature request Request for a new feature
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented Jan 27, 2023

Problem Description

The current API assumes that the custom constraint class is defined a Python file, and then imported/created in a different Python file. I would like the option to create a class and use it in the same file

This also makes demoing & internally testing a custom constraint a lot easier.

Expected behavior

In the new SDV 1.0 API, the workflow is changing a bit. When loading a constraint class from a different file, we will offer this function:

synthesizer.load_custom_constraint_classes(
    filepath='my_custom_constraint.py',
    class_names=['MyCustomConstraint'])

When you want to do it from the same file, you will have the object. We should add a new function to add it.

synthesizer.add_custom_constraint_class(
    class_object=MyCustomConstraint,
    class_name='MyCustomConstraint' # the name to use when referring to the constraint
)

Then you can create constraints using the defined class_name:

constraint = {
  'constraint_class': 'class_name',
  'constraint_parameters': {
    'column_names': ['A', 'B'],
    'my_custom_parameter': 10
  }
}
@npatki npatki added the feature request Request for a new feature label Jan 27, 2023
@npatki npatki added this to the 1.0.0 milestone Jan 27, 2023
@npatki npatki changed the title Allow me to create a Custom Constraint Class and use it in the same file (filepath=None) Allow me to create a custom constraint class and use it in the same file Jan 31, 2023
@amontanez24 amontanez24 self-assigned this Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants