Example #1
0
def set_item(handle, uids, value):
    root = handle.root
    if hasattr(root, 'my_data_table'):
        handle.remove_node(root, 'my_data_table', recursive=True)
    table = IndexedDataContainerTable(root, 'my_data_table', expected_number=n)
    for uid in uids:
        table[uid] = value
Example #2
0
def main():
    try:
        print("""
        Benchmarking various operations on the IndexDataContainerTable.

        """)
        with closing(tables.open_file(filename, mode='w')) as handle:
            root = handle.root
            table = IndexedDataContainerTable(root, 'my_data_table')
            print("Append {}:".format(n),
                  bench(lambda: append(handle, 1000, data_container)))

        with closing(tables.open_file(filename, mode='w')) as handle:
            root = handle.root
            table = IndexedDataContainerTable(root,
                                              'my_data_table',
                                              expected_number=n)
            print("Append {} masked:".format(n),
                  bench(lambda: append(handle, 1000, data_container_half)))

        uids = create_table(filename)
        sample = random.sample(uids, 300)

        with closing(tables.open_file(filename, mode='r')) as handle:
            root = handle.root
            table = IndexedDataContainerTable(root,
                                              'my_data_table',
                                              expected_number=n)
            print("Iterate {}:".format(n), bench(lambda: iteration(table)))
            print('Getitem sample of 300:',
                  bench(lambda: getitem_access(table, sample)))

        with closing(tables.open_file(filename, mode='a')) as handle:
            root = handle.root
            table = IndexedDataContainerTable(root,
                                              'my_data_table',
                                              expected_number=n)
            print("Update item of 300 sample:",
                  bench(lambda: setitem(table, data_container_half, sample)))
    finally:
        shutil.rmtree(temp_dir)
Example #3
0
 def open_table(self, table_name, mode='r'):
     handle = None
     try:
         handle = tables.open_file(self.filename, mode=mode)
         root = handle.root
         table = IndexedDataContainerTable(root,
                                           table_name,
                                           record=self.record)
         yield table
     finally:
         if handle is not None:
             handle.close()
Example #4
0
 def new_table(self, table_name):
     handle = None
     try:
         handle = tables.open_file(self.filename, mode='w')
         root = handle.root
         table = IndexedDataContainerTable(root,
                                           table_name,
                                           record=self.record)
         self.assertEqual(len(table), 0)
         yield table
     finally:
         if handle is not None:
             handle.close()
 def test_creating_a_data_container_table_using_default_record(self):
     with closing(tables.open_file(self.filename, mode='w')) as handle:
         root = handle.root
         table = IndexedDataContainerTable(root, 'my_data_table')
         self.assertEqual(len(table), 0)
         self.assertIn('my_data_table', root)
         self.assertTrue(table.valid)
         data_column = root.my_data_table.colinstances['data']
         expected_column_names = [
             key.name.lower() for key in self.saved_keys
         ]
         self.assertItemsEqual(data_column._v_colnames,
                               expected_column_names)
Example #6
0
def append(handle, n, value):
    root = handle.root
    if hasattr(root, 'my_data_table'):
        handle.remove_node(root, 'my_data_table', recursive=True)
    table = IndexedDataContainerTable(root, 'my_data_table', expected_number=n)
    return [table.append(value) for i in range(n)]