lale.type_checking module¶
Lale uses JSON Schema to check machine-learning pipelines for correct types.
In general, there are two kinds of checks. The first is an instance check (v: s), which checks whether a JSON value v is valid for a schema s. The second is a subschema check (s <: t), which checks whether one schema s is a subchema of another schema t.
Besides regular JSON values, Lale also supports certain JSON-like
values. For example, a np.ndarray
of numbers is treated like a
JSON array of arrays of numbers. Furthermore, Lale supports an ‘Any’
type for which all instance and subschema checks on the left as well
as the right side succeed. This is specified using {'laleType': 'Any'}
.
- exception lale.type_checking.SubschemaError(sub, sup, sub_name='sub', sup_name='super')[source]¶
Bases:
Exception
Raised when a subschema check (sub <: sup) failed.
- lale.type_checking.always_validate_schema(value: Any, schema: Dict[str, Any], subsample_array: bool = True)[source]¶
Validate that the value is an instance of the schema.
- Parameters
- Raises
jsonschema.ValidationError – The value was invalid for the schema.
- lale.type_checking.get_default_schema(impl)[source]¶
Creates combined schemas for a bare operator implementation class.
Used when there were no explicit combined schemas provided when the operator was created. The default schema provides defaults by inspecting the signature of the
__init__
method, and uses ‘Any’ types for the inputs and outputs of other methods.- Returns
Combined schema with properties for hyperparams and all applicable method inputs and outputs.
- Return type
JSON Schema
- lale.type_checking.get_hyperparam_names(op: IndividualOp) List[str] [source]¶
Names of the arguments to the constructor of the impl.
- Parameters
op (lale.operators.IndividualOp) – Operator whose hyperparameters to get.
- Returns
List of hyperparameter names.
- Return type
List[str]
- lale.type_checking.is_subschema(sub_schema: Dict[str, Any], super_schema: Dict[str, Any]) bool [source]¶
Is sub_schema a subschema of super_schema?
- Parameters
sub_schema (JSON schema) – Left-hand side of subschema check.
super_schema (JSON schema) – Right-hand side of subschema check.
- Returns
True if sub_schema <: super_schema, False otherwise.
- Return type
- Raises
jsonschema.ValueError – An error occured while checking the subschema relation
- lale.type_checking.join_schemas(*schemas: Dict[str, Any]) Dict[str, Any] [source]¶
Compute the lattice join (union type, disjunction) of the arguments.
- Parameters
*schemas (list of JSON schemas) – Schemas to be joined.
- Returns
The joined schema.
- Return type
JSON schema
- lale.type_checking.replace_data_constraints(hyperparam_schema: Dict[str, Any], data_schema: Dict[str, Any]) Dict[str, Any] [source]¶
- lale.type_checking.validate_method(op: IndividualOp, schema_name: str)[source]¶
Check whether the operator has the given method schema.
- Parameters
op (lale.operators.IndividualOp) – Operator whose methods to check.
schema_name ('input_fit' or 'input_predict' or 'input_predict_proba' or 'input_transform' 'output_predict' or 'output_predict_proba' or 'output_transform') – Name of schema to check.
- Raises
AssertionError – The operator does not have the given schema.
- lale.type_checking.validate_schema(lhs: Any, super_schema: Dict[str, Any])[source]¶
Validate that lhs is an instance of or a subschema of super_schema.
- Parameters
lhs (value) – Left-hand side of instance or subschema check.
super_schema (JSON schema) – Right-hand side of instance or subschema check.
- Raises
jsonschema.ValidationError – The lhs was an invalid value for super_schema.
SubschemaError – The lhs had a schema that was not a subschema of super_schema.