Skip to content

Commit e3ae189

Browse files
committed
ENH: allow tables to be specified w/o using 'table' under the group node (only for GenericTable)
1 parent 314b574 commit e3ae189

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pandas/io/pytables.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ def create_table_index(self, key, **kwargs):
611611

612612
def groups(self):
613613
""" return a list of all the top-level nodes (that are not themselves a pandas storage object) """
614-
return [ g for g in self.handle.walkGroups() if getattr(g._v_attrs,'pandas_type',None) or getattr(g,'table',None) ]
614+
_tables()
615+
return [ g for g in self.handle.walkGroups() if getattr(g._v_attrs,'pandas_type',None) or getattr(g,'table',None) or isinstance(g,_table_mod.table.Table) ]
615616

616617
def get_node(self, key):
617618
""" return the node with the key or None if it does not exist """
@@ -687,7 +688,8 @@ def error(t):
687688
if pt is None:
688689
if value is None:
689690

690-
if getattr(group,'table',None):
691+
_tables()
692+
if getattr(group,'table',None) or isinstance(group,_table_mod.table.Table):
691693
pt = 'frame_table'
692694
tt = 'generic_table'
693695
else:
@@ -2551,8 +2553,6 @@ def write_data_chunk(self, indexes, mask, search, values):
25512553
self.table.append(rows)
25522554
self.table.flush()
25532555
except (Exception), detail:
2554-
import pdb
2555-
pdb.set_trace()
25562556
raise Exception(
25572557
"tables cannot write this data -> %s" % str(detail))
25582558

@@ -2675,6 +2675,10 @@ class GenericTable(AppendableFrameTable):
26752675
def pandas_type(self):
26762676
return self.pandas_kind
26772677

2678+
@property
2679+
def storable(self):
2680+
return getattr(self.group,'table',None) or self.group
2681+
26782682
def get_attrs(self):
26792683
""" retrieve our attributes """
26802684
self.non_index_axes = []

pandas/io/tests/test_pytables.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,8 +1748,9 @@ def _check_roundtrip_table(self, obj, comparator, compression=False):
17481748
def test_pytables_native_read(self):
17491749
pth = curpath()
17501750
store = HDFStore(os.path.join(pth, 'pytables_native.h5'), 'r')
1751-
d = store['detector']
1752-
str(store)
1751+
d1 = store['detector']
1752+
d2 = store['detector/table']
1753+
assert_frame_equal(d1, d2)
17531754
store.close()
17541755

17551756
def test_legacy_read(self):

0 commit comments

Comments
 (0)