-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdfstorehelper.py
63 lines (52 loc) · 1.41 KB
/
hdfstorehelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pandas import HDFStore
class HDFStoreHelper:
def __init__(self, path):
self.path = path
def __getitem__(self, item):
return self._get(item)
def __setitem__(self, key, value):
self._put(key, value)
def _put(self, path, obj):
s = HDFStore(self.path)
if path in s:
print("updating %s" % path)
s.remove(path)
s.close()
s = HDFStore(self.path)
s[path] = obj
s.flush(fsync=True)
s.close()
def _get(self, path):
s = HDFStore(self.path)
d = None
if path in s:
d = s[path]
s.close()
return d
def in_store(self, path):
s = HDFStore(self.path)
val = False
if path in s:
val = True
s.close()
return val
def remove(self, path):
s = HDFStore(self.path)
if path in s:
print("removing %s" % path)
s.remove(path)
s.flush(fsync=True)
s.close()
def get_children_paths(self, node_path):
s = HDFStore(self.path)
node = s.get_node(node_path)
children = []
for child, df in node._v_children.items():
children.append(df._v_pathname)
s.close()
return children
def get_group_names(self):
s = HDFStore(self.path)
names = s.keys()
s.close()
return names