❖ PrimaryToPrimaryKeySubset
Use the PrimaryToPrimaryKeySubset constraint when you have a 1-to-1 connection between the primary keys of two or more tables but only certain values are allowed to have connections.

Constraint API
This functionality is in Beta. At this time, select SDV Enterprise users have been invited to use this feature.
Create a PrimaryToPrimaryKeySubset
constraint.
Parameters:
(required)
main_table_name
: A string with the name of the main table that contains all the possible rows. Only some of these rows are allowed to be connected to other tables.(required)
conditional_column_name
: A string with the name of a column in the main table. The values of this column controls whether connections are allowed with other tables.(required)
relationships
: A dictionary that maps the name of each connected table with the conditional value that is allowed for the connection.
from sdv.cag import PrimaryToPrimaryKeySubset
my_constraint = PrimaryToPrimaryKeySubset(
main_table_name='Users',
conditional_column_name='Is Minor?',
relationships={
'Parental Info': [True]
})
Make sure that all the table and columns in you provide are in your Metadata, and have a primary key associated with them.
Usage
Apply the constraint to any SDV synthesizer. Then fit and sample as usual.
synthesizer = HSASynthesizer(metadata)
synthesizer.add_constraints([my_constraint])
synthesizer.fit(data)
synthetic_data = synthesizer.sample()
For more information about using predefined constraints, please see the Constraint-Augmented Generation tutorial.
Last updated