def test_override_output2(self): init_output_schema = self.sk_pca.get_schema('output') pca_output = schemas.AnyOf([ schemas.Array(schemas.Array(schemas.Float())), schemas.Array(schemas.Float()) ]) expected = { 'anyOf': [{ 'type': 'array', 'items': { 'type': 'array', 'items': { 'type': 'number' } } }, { 'type': 'array', 'items': { 'type': 'number' } }] } foo = self.sk_pca.customize_schema(output=pca_output) self.assertEqual(foo.get_schema('output'), expected) helpers.validate_is_schema(foo._schemas) self.assertEqual(self.sk_pca.get_schema('output'), init_output_schema)
def test_override_output2(self): init_output_schema = self.sk_pca.get_schema("output_transform") pca_output = schemas.AnyOf([ schemas.Array(schemas.Array(schemas.Float())), schemas.Array(schemas.Float()), ]) expected = { "anyOf": [ { "type": "array", "items": { "type": "array", "items": { "type": "number" } }, }, { "type": "array", "items": { "type": "number" } }, ] } foo = self.sk_pca.customize_schema(output_transform=pca_output) self.assertEqual(foo.get_schema("output_transform"), expected) lale.type_checking.validate_is_schema(foo._schemas) self.assertEqual(self.sk_pca.get_schema("output_transform"), init_output_schema)
def test_disable_schema_validation_pipeline(self): os.environ["LALE_DISABLE_SCHEMA_VALIDATION"]='True' from lale.lib.sklearn import PCA, LogisticRegression import lale.schemas as schemas lr_input = schemas.Object(required=['X', 'y'], X=schemas.AnyOf([ schemas.Array( schemas.Array( schemas.String())), schemas.Array( schemas.String())]), y=schemas.Array(schemas.String())) foo = LogisticRegression.customize_schema(input_fit=lr_input) abc = foo() pipeline = PCA() >> abc trained_pipeline = pipeline.fit(self.X_train, self.y_train) trained_pipeline.predict(self.X_test) os.environ["LALE_DISABLE_SCHEMA_VALIDATION"]='False'
def test_enable_schema_validation_pipeline(self): with EnableSchemaValidation(): import lale.schemas as schemas from lale.lib.sklearn import PCA, LogisticRegression lr_input = schemas.Object( required=["X", "y"], X=schemas.AnyOf([ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ]), y=schemas.Array(schemas.String()), ) foo = LogisticRegression.customize_schema(input_fit=lr_input) abc = foo() pipeline = PCA() >> abc with self.assertRaises(ValueError): trained_pipeline = pipeline.fit(self.X_train, self.y_train) trained_pipeline.predict(self.X_test)
def test_override_array_param(self): init = self.sk_pca.hyperparam_schema('copy') expected = {'type': 'array', 'minItems': 1, 'maxItems': 20, 'items': {'type': 'integer'}} foo = self.sk_pca.customize_schema( copy=schemas.Array(minItems=1, maxItems=20, items=schemas.Int())) self.assertEqual(foo.hyperparam_schema('copy'), expected) lale.type_checking.validate_is_schema(foo._schemas) self.assertEqual(self.sk_pca.hyperparam_schema('copy'), init)
def test_disable_schema_validation_pipeline(self): existing_flag = disable_data_schema_validation set_disable_data_schema_validation(True) import lale.schemas as schemas from lale.lib.sklearn import PCA, LogisticRegression lr_input = schemas.Object( required=["X", "y"], X=schemas.AnyOf([ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ]), y=schemas.Array(schemas.String()), ) foo = LogisticRegression.customize_schema(input_fit=lr_input) abc = foo() pipeline = PCA() >> abc trained_pipeline = pipeline.fit(self.X_train, self.y_train) trained_pipeline.predict(self.X_test) set_disable_data_schema_validation(existing_flag)
def test_disable_schema_validation_individual_op(self): os.environ["LALE_DISABLE_SCHEMA_VALIDATION"] = "True" import lale.schemas as schemas from lale.lib.sklearn import PCA pca_input = schemas.Object( X=schemas.AnyOf( [ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ] ) ) foo = PCA.customize_schema(input_fit=pca_input) pca_output = schemas.Object( X=schemas.AnyOf( [ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ] ) ) foo = foo.customize_schema(output_transform=pca_output) abc = foo() trained_pca = abc.fit(self.X_train) trained_pca.transform(self.X_test) os.environ["LALE_DISABLE_SCHEMA_VALIDATION"] = "False"
def test_enable_schema_validation_individual_op(self): existing_flag = disable_data_schema_validation set_disable_data_schema_validation(False) import lale.schemas as schemas from lale.lib.sklearn import PCA pca_input = schemas.Object(X=schemas.AnyOf([ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ])) foo = PCA.customize_schema(input_fit=pca_input) pca_output = schemas.Object(X=schemas.AnyOf([ schemas.Array(schemas.Array(schemas.String())), schemas.Array(schemas.String()), ])) foo = foo.customize_schema(output_transform=pca_output) abc = foo() with self.assertRaises(ValueError): trained_pca = abc.fit(self.X_train) trained_pca.transform(self.X_test) set_disable_data_schema_validation(existing_flag)
def test_override_array_param(self): init = self.sk_pca.hyperparam_schema("copy") expected = { "type": "array", "minItems": 1, "maxItems": 20, "items": {"type": "integer"}, } foo = self.sk_pca.customize_schema( copy=schemas.Array(minItems=1, maxItems=20, items=schemas.Int()) ) self.assertEqual(foo.hyperparam_schema("copy"), expected) lale.type_checking.validate_is_schema(foo._schemas) self.assertEqual(self.sk_pca.hyperparam_schema("copy"), init)
def test_override_object_param(self): init = self.sk_pca.get_schema('input_fit') expected = {'type': 'object', 'required': ['X'], 'additionalProperties': False, 'properties': { 'X': {'type': 'array', 'items': { 'type': 'number'}}}} foo = self.sk_pca.customize_schema( input_fit=schemas.Object(required=['X'], additionalProperties=False, X=schemas.Array(schemas.Float()))) self.assertEqual(foo.get_schema('input_fit'), expected) lale.type_checking.validate_is_schema(foo.get_schema('input_fit')) self.assertEqual(self.sk_pca.get_schema('input_fit'), init)
def test_override_object_param(self): init = self.sk_pca.get_schema("input_fit") expected = { "type": "object", "required": ["X"], "additionalProperties": False, "properties": {"X": {"type": "array", "items": {"type": "number"}}}, } foo = self.sk_pca.customize_schema( input_fit=schemas.Object( required=["X"], additionalProperties=False, X=schemas.Array(schemas.Float()), ) ) self.assertEqual(foo.get_schema("input_fit"), expected) lale.type_checking.validate_is_schema(foo.get_schema("input_fit")) self.assertEqual(self.sk_pca.get_schema("input_fit"), init)
def test_override_object_param(self): init = self.sk_pca.get_schema('input_fit') expected = { '$schema': 'http://json-schema.org/draft-04/schema#', 'type': 'object', 'required': ['X'], 'additionalProperties': False, 'properties': { 'X': { 'type': 'array', 'items': { 'type': 'number' } } } } foo = self.sk_pca.customize_schema(input_fit=schemas.Object( required=['X'], additionalProperties=False, properties={'X': schemas.Array(schemas.Float())})) self.assertEqual(foo.get_schema('input_fit'), expected) helpers.validate_is_schema(foo.get_schema('input_fit')) self.assertEqual(self.sk_pca.get_schema('input_fit'), init)