Skip to content

Commit 3726a49

Browse files
committed
HDFStore __unicode__ now only returns file path info, not (expensive) details on all existing keys. New info() method has the previous behavior of __unicode__.
1 parent 75c8698 commit 3726a49

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

pandas/io/pytables.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -494,32 +494,7 @@ def __len__(self):
494494
return len(self.groups())
495495

496496
def __unicode__(self):
497-
output = '%s\nFile path: %s\n' % (type(self), pprint_thing(self._path))
498-
if self.is_open:
499-
lkeys = sorted(list(self.keys()))
500-
if len(lkeys):
501-
keys = []
502-
values = []
503-
504-
for k in lkeys:
505-
try:
506-
s = self.get_storer(k)
507-
if s is not None:
508-
keys.append(pprint_thing(s.pathname or k))
509-
values.append(
510-
pprint_thing(s or 'invalid_HDFStore node'))
511-
except Exception as detail:
512-
keys.append(k)
513-
values.append("[invalid_HDFStore node: %s]"
514-
% pprint_thing(detail))
515-
516-
output += adjoin(12, keys, values)
517-
else:
518-
output += 'Empty'
519-
else:
520-
output += "File is CLOSED"
521-
522-
return output
497+
return '%s\nFile path: %s\n' % (type(self), pprint_thing(self._path))
523498

524499
def __enter__(self):
525500
return self
@@ -1161,6 +1136,35 @@ def copy(self, file, mode='w', propindexes=True, keys=None, complib=None,
11611136

11621137
return new_store
11631138

1139+
def info(self):
1140+
"""return detailed information on the store"""
1141+
output = '%s\nFile path: %s\n' % (type(self), pprint_thing(self._path))
1142+
if self.is_open:
1143+
lkeys = sorted(list(self.keys()))
1144+
if len(lkeys):
1145+
keys = []
1146+
values = []
1147+
1148+
for k in lkeys:
1149+
try:
1150+
s = self.get_storer(k)
1151+
if s is not None:
1152+
keys.append(pprint_thing(s.pathname or k))
1153+
values.append(
1154+
pprint_thing(s or 'invalid_HDFStore node'))
1155+
except Exception as detail:
1156+
keys.append(k)
1157+
values.append("[invalid_HDFStore node: %s]"
1158+
% pprint_thing(detail))
1159+
1160+
output += adjoin(12, keys, values)
1161+
else:
1162+
output += 'Empty'
1163+
else:
1164+
output += "File is CLOSED"
1165+
1166+
return output
1167+
11641168
# private methods ######
11651169
def _check_if_open(self):
11661170
if not self.is_open:

0 commit comments

Comments
 (0)