def test_expand_defaults_unknown_schema_type(self): schema = [{'name': 'col1', 'type': 'BYTES'}, {'name': 'col2', 'type': 'INTEGER'}] features = {'col1': {'transform': 'x'}, 'col2': {'transform': 'y'}} with self.assertRaises(ValueError): analyze.expand_defaults(schema, features)
def test_expand_defaults_unknown_schema_type(self): schema = [{ 'name': 'col1', 'type': 'BYTES' }, { 'name': 'col2', 'type': 'INTEGER' }] features = {'col1': {'transform': 'x'}, 'col2': {'transform': 'y'}} with self.assertRaises(ValueError): analyze.expand_defaults(schema, features)
def test_expand_defaults_do_nothing(self): schema = [{'name': 'col1', 'type': 'FLOAT'}, {'name': 'col2', 'type': 'INTEGER'}] features = {'col1': {'transform': 'x'}, 'col2': {'transform': 'y'}} expected_features = { 'col1': {'transform': 'x', 'source_column': 'col1'}, 'col2': {'transform': 'y', 'source_column': 'col2'}} analyze.expand_defaults(schema, features) # Nothing should change. self.assertEqual(expected_features, features)
def test_expand_defaults(self): schema = [{'name': 'col1', 'type': 'FLOAT'}, {'name': 'col2', 'type': 'INTEGER'}, {'name': 'col3', 'type': 'STRING'}, {'name': 'col4', 'type': 'FLOAT'}, {'name': 'col5', 'type': 'INTEGER'}, {'name': 'col6', 'type': 'STRING'}] features = {'col1': {'transform': 'x'}, 'col2': {'transform': 'y'}, 'col3': {'transform': 'z'}} analyze.expand_defaults(schema, features) self.assertEqual( features, {'col1': {'transform': 'x', 'source_column': 'col1'}, 'col2': {'transform': 'y', 'source_column': 'col2'}, 'col3': {'transform': 'z', 'source_column': 'col3'}, 'col4': {'transform': 'identity', 'source_column': 'col4'}, 'col5': {'transform': 'identity', 'source_column': 'col5'}, 'col6': {'transform': 'one_hot', 'source_column': 'col6'}})
def test_expand_defaults_do_nothing(self): schema = [{ 'name': 'col1', 'type': 'FLOAT' }, { 'name': 'col2', 'type': 'INTEGER' }] features = {'col1': {'transform': 'x'}, 'col2': {'transform': 'y'}} expected_features = { 'col1': { 'transform': 'x', 'source_column': 'col1' }, 'col2': { 'transform': 'y', 'source_column': 'col2' } } analyze.expand_defaults(schema, features) # Nothing should change. self.assertEqual(expected_features, features)
def test_expand_defaults(self): schema = [{ 'name': 'col1', 'type': 'FLOAT' }, { 'name': 'col2', 'type': 'INTEGER' }, { 'name': 'col3', 'type': 'STRING' }, { 'name': 'col4', 'type': 'FLOAT' }, { 'name': 'col5', 'type': 'INTEGER' }, { 'name': 'col6', 'type': 'STRING' }] features = { 'col1': { 'transform': 'x' }, 'col2': { 'transform': 'y' }, 'col3': { 'transform': 'z' } } analyze.expand_defaults(schema, features) self.assertEqual( features, { 'col1': { 'transform': 'x', 'source_column': 'col1' }, 'col2': { 'transform': 'y', 'source_column': 'col2' }, 'col3': { 'transform': 'z', 'source_column': 'col3' }, 'col4': { 'transform': 'identity', 'source_column': 'col4' }, 'col5': { 'transform': 'identity', 'source_column': 'col5' }, 'col6': { 'transform': 'one_hot', 'source_column': 'col6' } })