Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_is_ref(self):
spec = DtypeSpec('column1', 'an example column', RefSpec('TimeSeries', 'object'))
self.assertTrue(DtypeSpec.is_ref(spec))
spec = DtypeSpec('column1', 'an example column', 'int')
self.assertFalse(DtypeSpec.is_ref(spec))
def test_datatype_table_extension(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column3', 'the third column', 'str')
ext = DatasetSpec('my first table extension',
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')
self.assertEqual(ext['dtype'], [dtype1, dtype2, dtype3])
self.assertEqual(ext['doc'], 'my first table extension')
def test_datatype_table_extension_higher_precision(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float32')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'float64')
ext = DatasetSpec('my first table extension',
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')
self.assertEqual(ext['dtype'], [dtype1, dtype3])
self.assertEqual(ext['doc'], 'my first table extension')
def test_simplify_cpd_type(self):
compound_type = [DtypeSpec('test', 'test field', 'float'),
DtypeSpec('test2', 'test field2', 'int')]
expected_result = ['float', 'int']
result = DtypeHelper.simplify_cpd_type(compound_type)
self.assertListEqual(result, expected_result)
def test_invalid_refspec_dict(self):
with self.assertRaises(AssertionError):
DtypeSpec.assertValidDtype({'no target': 'test', # <-- missing or here bad target key for RefSpec
'reftype': 'object'})
def test_datatype_table_extension(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column3', 'the third column', 'str')
ext = DatasetSpec('my first table extension',
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')
self.assertEqual(ext['dtype'], [dtype1, dtype2, dtype3])
self.assertEqual(ext['doc'], 'my first table extension')
def test_datatype_table_extension_lower_precision(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float64')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'float32')
with self.assertRaisesRegex(ValueError, 'Cannot extend float64 to float32'):
ext = DatasetSpec('my first table extension', # noqa: F841
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')
def test_datatype_table_extension_higher_precision(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float32')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'float64')
ext = DatasetSpec('my first table extension',
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')
self.assertEqual(ext['dtype'], [dtype1, dtype3])
self.assertEqual(ext['doc'], 'my first table extension')
def test_datatype_table_extension_lower_precision(self):
dtype1 = DtypeSpec('column1', 'the first column', 'int')
dtype2 = DtypeSpec('column2', 'the second column', 'float64')
base = DatasetSpec('my first table',
[dtype1, dtype2],
attributes=self.attributes,
namespace='core',
data_type_def='SimpleTable')
self.assertEqual(base['dtype'], [dtype1, dtype2])
self.assertEqual(base['doc'], 'my first table')
dtype3 = DtypeSpec('column2', 'the second column, with greater precision', 'float32')
with self.assertRaisesRegex(ValueError, 'Cannot extend float64 to float32'):
ext = DatasetSpec('my first table extension', # noqa: F841
[dtype3],
namespace='core',
data_type_inc=base,
data_type_def='ExtendedTable')