Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_empty_table(self, table):
self.assertIsInstance(table.columns[0], VectorData)
self.assertEqual(len(table.columns), 3)
self.assertEqual(table.colnames, ('foo', 'bar', 'baz'))
def test_constructor_ids_bad_ids(self):
columns = [VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)]
msg = "must provide same number of ids as length of columns"
with self.assertRaisesRegex(ValueError, msg):
DynamicTable("with_columns", 'a test table', id=[0, 1], columns=columns)
def test_nd_array_to_df(self):
data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
col = VectorData(name='name', description='desc', data=data)
df = DynamicTable('test', 'desc', np.arange(3, dtype='int'), (col, )).to_dataframe()
df2 = pd.DataFrame({'name': [x for x in data]},
index=pd.Index(name='id', data=[0, 1, 2]))
assert_frame_equal(df, df2)
def test_constructor_ids(self):
columns = [VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)]
table = DynamicTable("with_columns", 'a test table', id=[0, 1, 2, 3, 4], columns=columns)
self.check_table(table)
def with_table_columns(self):
cols = [VectorData(**d) for d in self.spec]
table = DynamicTable("with_table_columns", 'a test table', columns=cols)
return table
def test_constructor_ids_bad_ids(self):
columns = [VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)]
msg = "must provide same number of ids as length of columns"
with self.assertRaisesRegex(ValueError, msg):
DynamicTable("with_columns", 'a test table', id=[0, 1], columns=columns)
def with_columns_and_data(self):
columns = [
VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)
]
return DynamicTable("with_columns_and_data", 'a test table', columns=columns)
def test_constructor_ids_default(self):
columns = [VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)]
table = DynamicTable("with_spec", 'a test table', columns=columns)
self.check_table(table)
def with_columns_and_data(self):
columns = [
VectorData(name=s['name'], description=s['description'], data=d)
for s, d in zip(self.spec, self.data)
]
return DynamicTable("with_columns_and_data", 'a test table', columns=columns)