From 85bb46f45cd4c1fae3badb4efabe3ff3ce131466 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 4 Dec 2012 18:57:36 -0500 Subject: [PATCH] Use pytable's createparents flag to avoid having to create group structure manually. --- nilmdb/nilmdb.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/nilmdb/nilmdb.py b/nilmdb/nilmdb.py index af0ecfd..453bd3f 100644 --- a/nilmdb/nilmdb.py +++ b/nilmdb/nilmdb.py @@ -291,16 +291,6 @@ class NilmDB(object): if group == '': raise ValueError("invalid path") - # Make the group structure, one element at a time - group_path = group.lstrip('/').split("/") - for i in range(len(group_path)): - parent = "/" + "/".join(group_path[0:i]) - child = group_path[i] - try: - self.h5file.createGroup(parent, child) - except tables.NodeError: - pass - # Get description try: desc = nilmdb.layout.get_named(layout_name).description() @@ -314,7 +304,8 @@ class NilmDB(object): # Create the table table = self.h5file.createTable(group, node, description = desc, - expectedrows = exp_rows) + expectedrows = exp_rows, + createparents = True) # Insert into SQL database once the PyTables is happy with self.con as con: