Skip to content

schema validation for bare sparseness constraint #838

Description

@hirzel

Currently, schema-checking raises an internal assertion for constraints of the form X/isSparse that are "bare", i.e., not inside of an anyOf.

Test to reproduce:

import jsonschema
import scipy.sparse
import sklearn.datasets
import sklearn.decomposition
import unittest
import lale.lib.sklearn

class TestBareSparsenessConstraint(unittest.TestCase):
    def setUp(self):
        X, y = sklearn.datasets.load_iris(return_X_y=True)
        self.sparse_X = scipy.sparse.csr_matrix(X)
        self.y = y

    def test_bare_sparseness_constraint(self):
        #without Lale
        trainable = sklearn.decomposition.PCA()
        with self.assertRaisesRegex(TypeError, "PCA does not support sparse"):
            trained = trainable.fit(self.sparse_X, self.y)
        #with Lale and schema validation
        with EnableSchemaValidation():
            trainable = lale.lib.sklearn.PCA()
            with self.assertRaises(jsonschema.ValidationError):
                trained = trainable.fit(self.sparse_X, self.y)

Output:

  File "lale/lale/operators.py", line 1984, in _validate_hyperparams
    assert e.schema_path[2] == "anyOf"
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions