synthcity.plugins.core.constraints module
- class Constraints(*, rules: list = [])
Bases:
pydantic.main.BaseModel
Constraints on data.
The Constraints class allows users to specify constraints on the features. Examples include the feature value range, allowed item set, and data type. These constraints can be used to filter out invalid values in synthetic datasets.
- Constructor Args:
- rules: List[Tuple]
Each tuple in the list specifies a constraint on a feature. The tuple has the form of (feature, op, thresh), where feature is the feature name to apply constraint on, op takes values in [
“<”, “>=”, “<=”, “>”, “==”, “lt”, “le”, “gt”, “ge”, “eq”, “in”, “dtype”,
],
and thresh is the threshold or data type.
- Config
alias of
pydantic.config.BaseConfig
- classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep – set to True to make a deep copy of the model
- Returns
new model instance
- dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- extend(other: synthcity.plugins.core.constraints.Constraints) synthcity.plugins.core.constraints.Constraints
Extend the local constraints with more constraints.
- Parameters
other – The new constraints to add.
- Returns
self with the updated constraints.
- feature_constraints(ref_feature: str) List
Get constraints for a given feature
- Parameters
ref_feature – str The name of the feature of interest.
- Returns
[(‘le’, 3.), (‘gt’, 1.)]
If ref_feature has no constraint, None will be returned.
- Return type
A list of tuples of (op, threshold) For example
- feature_params(feature: str) Tuple
Provide the parameters of Distribution from the Constraint
This is to be used with the constraint_to_distribution function in distribution module.
- Parameters
feature – str The name of the feature of interest.
- Returns
- str
The type of inferred distribution from (“categorical”, “float”, “integer”)
- dist_args: Dict
The arguments to the constructor of the Distribution.
- Return type
dist_template
- features() List
Return list of feature names in an undefined order
- filter(X: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame
Apply the constraints to a DataFrame X.
- Parameters
X – DataFrame. The dataset to apply the constraints on.
- Returns
pandas.Index which matches all the constraints
- classmethod from_orm(obj: Any) Model
- is_valid(X: pandas.core.frame.DataFrame) bool
Checks if all the rows in X meet the constraints.
- Parameters
X – DataFrame. The dataset to apply the constraints on.
- Returns
True if all rows match the constraints, False otherwise
- json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- match(X: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame
Apply the constraints to a DataFrame X and return the filtered dataset.
- Parameters
X – DataFrame. The dataset to apply the constraints on.
- Returns
The filtered Dataframe
- classmethod parse_file(path: Union[str, pathlib.Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: pydantic.parse.Protocol = None, allow_pickle: bool = False) Model
- classmethod parse_obj(obj: Any) Model
- classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: pydantic.parse.Protocol = None, allow_pickle: bool = False) Model
- rules: list
- classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') DictStrAny
- classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) unicode
- classmethod update_forward_refs(**localns: Any) None
Try to update ForwardRefs on fields based on this Model, globalns and localns.
- classmethod validate(value: Any) Model