def math_unary_deserialize_exp_test(self): math_unary_tf = MathUnary(input_features=['a'], output_features=['log_a'], transform_type='exp') Xres = math_unary_tf.fit_transform(self.df.a) self.assertEqual(np.exp(self.df.a[0]), Xres[0]) math_unary_tf.serialize_to_bundle(self.tmp_dir, math_unary_tf.name) node_name = "{}.node".format(math_unary_tf.name) math_unary_ds_tf = MathUnary() math_unary_ds_tf = math_unary_ds_tf.deserialize_from_bundle( self.tmp_dir, node_name) with open("{}/{}.node/model.json".format( self.tmp_dir, math_unary_tf.name)) as json_data: model = json.load(json_data) res_a = math_unary_tf.transform(self.df['a']) res_b = math_unary_ds_tf.transform(self.df['a']) self.assertEqual(res_a[0], res_b[0])
def math_unary_sin_test(self): math_unary_tf = MathUnary(input_features=['a'], output_features=['sin_a'], transform_type='sin') Xres = math_unary_tf.fit_transform(self.df.a) self.assertEqual(np.sin(self.df.a[0]), Xres[0]) math_unary_tf.serialize_to_bundle(self.tmp_dir, math_unary_tf.name) expected_model = { "op": "math_unary", "attributes": { "operation": { "type": "string", "value": 'sin' } } } # Test model.json with open("{}/{}.node/model.json".format(self.tmp_dir, math_unary_tf.name)) as json_data: model = json.load(json_data) self.assertEqual(expected_model['attributes']['operation']['value'], model['attributes']['operation']['value']) # Test node.json with open("{}/{}.node/node.json".format(self.tmp_dir, math_unary_tf.name)) as json_data: node = json.load(json_data) self.assertEqual(math_unary_tf.name, node['name']) self.assertEqual(math_unary_tf.input_features[0], node['shape']['inputs'][0]['name']) self.assertEqual(math_unary_tf.output_features[0], node['shape']['outputs'][0]['name'])