Beispiel #1
0
    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"
Beispiel #2
0
    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)
Beispiel #3
0
    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'
Beispiel #4
0
    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)
Beispiel #5
0
    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)