def test_param_schema_explicit(self): spec = ModuleSpec( id_name="x", name="x", category="Clean", parameters=[{ "id_name": "whee", "type": "custom" }], param_schema={ "id_name": { "type": "dict", "properties": { "x": { "type": "integer" }, "y": { "type": "string", "default": "X" }, }, } }, ) self.assertEqual( spec.get_param_schema(), ParamDType.Dict({ "id_name": ParamDType.Dict({ "x": ParamDType.Integer(), "y": ParamDType.String(default="X") }) }), )
def test_clean_normal_dict(self): context = self._render_context() schema = ParamDType.Dict( {"str": ParamDType.String(), "int": ParamDType.Integer()} ) value = {"str": "foo", "int": 3} expected = dict(value) # no-op result = clean_value(schema, value, context) self.assertEqual(result, expected)
def test_clean_normal_dict(self): input_shape = TableMetadata(3, [Column("A", ColumnType.Number())]) schema = ParamDType.Dict({ "str": ParamDType.String(), "int": ParamDType.Integer() }) value = {"str": "foo", "int": 3} expected = dict(value) # no-op result = clean_value(schema, value, input_shape) self.assertEqual(result, expected)
def test_list_dtype(self): # Check that ParamSpec's with List type produce correct nested DTypes param_spec = ParamSpec.from_dict( dict( id_name="p", type="list", child_parameters=[ { "id_name": "intparam", "type": "integer", "name": "my number" }, { "id_name": "colparam", "type": "column", "name": "my column" }, ], )) self.assertEqual( param_spec, ParamSpec.List( id_name="p", child_parameters=[ ParamSpec.Integer(id_name="intparam", name="my number"), ParamSpec.Column(id_name="colparam", name="my column"), ], ), ) dtype = param_spec.dtype expected_dtype = DT.List( DT.Dict({ "intparam": DT.Integer(), "colparam": DT.Column() })) # effectively do a deep compare with repr self.assertEqual(repr(dtype), repr(expected_dtype))
def dtype(self) -> Optional[ParamDType]: return ParamDType.Integer(self.default)