❖ ForeignToPrimaryKeySubset
Use the ForeignToPrimaryKeySubset constraint when you have a 1-to-many connection between tables, but only certain values are allowed to have connections.

Constraint API
Create a ForeignToPrimaryKeySubset
constraint.
Parameters:
(required)
parent_table_name
: A string with the name of the parent table in the relationship(required)
child_table_name
: A string with the name of the child table in the relationship(required)
child_foreign_key
: A string with the name of the foreign key column in the child. This column is only allowed to be connected to the parent table with certain values.(required)
conditional_column_name
: A string with the name of the conditional column in the parent table. The values in this column determine which connections are allowed.(required)
conditional_values
: A list of values of the conditional column. Only these particular values are allowed to have connections with the child table.
from sdv.cag import ForeignToPrimaryKeySubset
my_constraint = ForeignToPrimaryKeySubset(
parent_table_name='Accounts',
child_table_name='Perks',
child_foreign_key='ID',
conditional_column_name='Type',
conditional_values=['PREMIUM'])
Make sure that all the tables and columns you provide are listed in your Metadata, as well as the relationship between the primary and foreign key.
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