def setUpClass(cls): data_loader = CSVDataLoader('tests/data/meta.json') cls.data_navigator = data_loader.load_data() cls.data_navigator.transform_data() cls.modeler = Modeler(cls.data_navigator) cls.modeler.model_database()
def fit(self): """Transform the data and model the database.""" data_loader = CSVDataLoader(self.meta_file_name) self.dn = data_loader.load_data() # transform data self.dn.transform_data() self.modeler = Modeler(self.dn) self.modeler.model_database() self.sampler = Sampler(self.dn, self.modeler)
def fit(self): """Transform the data and model the database. Raises: ValueError: If the provided dataset has an unsupported structure. """ data_loader = CSVDataLoader(self.meta_file_name) self.dn = data_loader.load_data() self._check_unsupported_dataset_structure() self.dn.transform_data() self.modeler = Modeler(self.dn) self.modeler.model_database() self.sampler = Sampler(self.dn, self.modeler)
def test__format_table_meta(self): """format table meta dict""" # Setup # Run meta = {'fields': [{'name': 'a_field', 'foo': 'foo'}]} csv_data_loader_mock = Mock() result = CSVDataLoader._format_table_meta(csv_data_loader_mock, meta) # Asserts expect = {'fields': {'a_field': {'name': 'a_field', 'foo': 'foo'}}} assert result == expect
def setUp(self): """Set up test fixtures, if any.""" dl = CSVDataLoader('tests/data/meta.json') self.dn = dl.load_data() self.dn.transform_data() self.modeler = Modeler(self.dn)
def test_load_data(self, read_mock, dn_mock): """load_data to build a DataNavigator""" # SetUp meta = { 'path': '', 'tables': [{ 'use': True, 'name': 'DEMO', 'path': 'some_path.csv', 'fields': [{ 'name': 'a_field', 'foo': 'foo' }] }] } meta_filename = 'meta_filename.json' dn_mock.return_value = Mock() format_mock = Mock() format_mock.return_value = {'some': 'meta'} read_mock.return_value = pd.DataFrame({'foo': [0, 1]}) # Run csv_data_loader_mock = Mock() csv_data_loader_mock.meta = meta csv_data_loader_mock.meta_filename = meta_filename csv_data_loader_mock._format_table_meta = format_mock CSVDataLoader.load_data(csv_data_loader_mock) # Asserts exp_format_args = { 'use': True, 'name': 'DEMO', 'path': 'some_path.csv', 'fields': [{ 'name': 'a_field', 'foo': 'foo' }] } exp_data_navigator_meta = { 'path': '', 'tables': [{ 'use': True, 'name': 'DEMO', 'path': 'some_path.csv', 'fields': [{ 'name': 'a_field', 'foo': 'foo' }] }] } exp_data_navigator_tables = { 'DEMO': Table(pd.DataFrame({'foo': [0, 1]}), {'some': 'meta'}) } assert_meta_filename, assert_meta, assert_tables = dn_mock.call_args[0] format_mock.assert_called_once_with(exp_format_args) assert assert_meta_filename == 'meta_filename.json' assert assert_meta == exp_data_navigator_meta assert assert_tables.keys() == exp_data_navigator_tables.keys() pd.testing.assert_frame_equal(assert_tables['DEMO'].data, exp_data_navigator_tables['DEMO'].data)
def setUp(self): data_loader = CSVDataLoader('tests/data/meta.json') self.data_navigator = data_loader.load_data()