def test_File_delimiter(self) -> None: with self.subTest(format='rfc'): with csv.File(self.rfc_path) as file: self.assertEqual(file.delimiter, self.rfc_sep) with self.subTest(format='rlang'): with csv.File(self.rlang_path) as file: self.assertEqual(file.delimiter, self.rlang_sep)
def test_File_name(self) -> None: with self.subTest(format='rfc'): with csv.File(self.rfc_path) as file: self.assertEqual(file.name, self.rfc_path.name) with self.subTest(format='rlang'): with csv.File(self.rlang_path) as file: self.assertEqual(file.name, self.rlang_path.name)
def test_File_rownames(self) -> None: with self.subTest(format='rfc'): with csv.File(self.rfc_path) as file: self.assertEqual(file.rownames, None) with csv.File(self.rfc_path, namecol='name') as file: self.assertEqual(file.rownames, self.rownames) with self.subTest(format='rlang'): with csv.File(self.rlang_path) as file: self.assertEqual(file.rownames, self.rownames)
def test_File_init(self) -> None: with self.subTest(format='rfc'): with csv.File( self.rfc_path, header=self.rfc_header, comment=self.comment, delimiter=self.rfc_sep) as file: self.assertIsInstance(file, csv.File) with self.subTest(format='rlang'): with csv.File( self.rlang_path, header=self.rlang_header, comment=self.comment, delimiter=self.rlang_sep) as file: self.assertIsInstance(file, csv.File)
def load(self, path): """Get dataset configuration and dataset tables. Args: path (string): csv file containing dataset configuration and dataset table. """ # Get instance of CSV-file file = csv.File(path) # Get configuration from CSV comment lines comment = file.comment scheme = { 'name': str, 'branch': str, 'version': int, 'about': str, 'author': str, 'email': str, 'license': str, 'filetype': str, 'application': str, 'preprocessing': dict, 'type': str, 'labelformat': str } config = ini.decode(comment, flat=True, scheme=scheme) if 'name' in config: name = config['name'] else: name = env.basename(path) config['name'] = name if 'type' not in config: config['type'] = 'base.Dataset' # Add column and row filters config['colfilter'] = {'*': ['*:*']} config['rowfilter'] = {'*': ['*:*'], name: [name + ':*']} # Load data names = list(file.header) names[0] = 'label' data = array.from_tuples(file.read(), names=tuple(names)) config['table'] = {name: config.copy()} config['table'][name]['fraction'] = 1.0 config['columns'] = tuple() config['colmapping'] = {} config['table'][name]['columns'] = [] for column in data.dtype.names: if column == 'label': continue config['columns'] += (('', column), ) config['colmapping'][column] = column config['table'][name]['columns'].append(column) # Get data table from CSV data tables = {name: data} return {'config': config, 'tables': tables}