def test_validators(self): gt = ParamValidators.gt(10) self.assertFalse(gt.validate(None)) self.assertFalse(gt.validate(5)) self.assertFalse(gt.validate(10)) self.assertTrue(gt.validate(15)) gt_eq = ParamValidators.gt_eq(10) self.assertFalse(gt_eq.validate(None)) self.assertFalse(gt_eq.validate(5)) self.assertTrue(gt_eq.validate(10)) self.assertTrue(gt_eq.validate(15)) lt = ParamValidators.lt(10) self.assertFalse(lt.validate(None)) self.assertTrue(lt.validate(5)) self.assertFalse(lt.validate(10)) self.assertFalse(lt.validate(15)) lt_eq = ParamValidators.lt_eq(10) self.assertFalse(lt_eq.validate(None)) self.assertTrue(lt_eq.validate(5)) self.assertTrue(lt_eq.validate(10)) self.assertFalse(lt_eq.validate(15)) in_range_inclusive = ParamValidators.in_range(5, 15) self.assertFalse(in_range_inclusive.validate(None)) self.assertFalse(in_range_inclusive.validate(0)) self.assertTrue(in_range_inclusive.validate(5)) self.assertTrue(in_range_inclusive.validate(10)) self.assertTrue(in_range_inclusive.validate(15)) self.assertFalse(in_range_inclusive.validate(20)) in_range_exclusive = ParamValidators.in_range(5, 15, False, False) self.assertFalse(in_range_exclusive.validate(None)) self.assertFalse(in_range_exclusive.validate(0)) self.assertFalse(in_range_exclusive.validate(5)) self.assertTrue(in_range_exclusive.validate(10)) self.assertFalse(in_range_exclusive.validate(15)) self.assertFalse(in_range_exclusive.validate(20)) in_array = ParamValidators.in_array([1, 2, 3]) self.assertFalse(in_array.validate(None)) self.assertTrue(in_array.validate(1)) self.assertFalse(in_array.validate(0)) not_null = ParamValidators.not_null() self.assertTrue(not_null.validate(5)) self.assertFalse(not_null.validate(None))
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ import os from typing import Dict, Any from pyflink.table import StreamTableEnvironment from pyflink.ml.core.api import Stage from pyflink.ml.core.param import ParamValidators, Param, BooleanParam, IntParam, \ FloatParam, StringParam, IntArrayParam, FloatArrayParam, StringArrayParam from pyflink.ml.tests.test_utils import PyFlinkMLTestCase BOOLEAN_PARAM = BooleanParam("boolean_param", "Description", False) INT_PARAM = IntParam("int_param", "Description", 1, ParamValidators.lt(100)) FLOAT_PARAM = FloatParam("float_param", "Description", 3.0, ParamValidators.lt(100)) STRING_PARAM = StringParam('string_param', "Description", "5") INT_ARRAY_PARAM = IntArrayParam("int_array_param", "Description", (6, 7)) FLOAT_ARRAY_PARAM = FloatArrayParam("float_array_param", "Description", (10.0, 11.0)) STRING_ARRAY_PARAM = StringArrayParam("string_array_param", "Description", ("14", "15")) EXTRA_INT_PARAM = IntParam("extra_int_param", "Description", 20, ParamValidators.always_true()) PARAM_WITH_NONE_DEFAULT = IntParam( "param_with_none_default", "Must be explicitly set with a non-none value", None, ParamValidators.not_null())