Skip to content

Commit 06d55c0

Browse files
jrebackwesm
authored andcommitted
store.keys() now returns the ABSOLUTE path-name of the sub-stores (e.g always has a leading '/')
bug in __repr__ for tables - fixed
1 parent 37e7ef0 commit 06d55c0

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pandas 0.10.0
5757
- `obj.fillna()` is no longer valid; make `method='pad'` no longer the
5858
default option, to be more explicit about what kind of filling to
5959
perform. Add `ffill/bfill` convenience functions per above (#2284)
60+
- `HDFStore.keys()` now returns an absolute path-name for each key
6061

6162
**Improvements to existing features**
6263

doc/source/io.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ Keys to a store can be specified as a string. These can be in a hierarchical pat
877877
store.append('food/apple', df)
878878
store
879879
880+
# a list of keys are returned
881+
store.keys()
882+
880883
# remove all nodes under this level
881884
store.remove('food')
882885
store

doc/source/v0.10.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Updated PyTables Support
9090

9191
- performance improvments on table writing
9292
- support for arbitrarily indexed dimensions
93-
- ``SparseSeries`` now has a ``density`` property (#2384)
93+
- ``SparseSeries`` now has a ``density`` property (#2384)
9494

9595
**Bug Fixes**
9696

pandas/io/pytables.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,14 @@ def __delitem__(self, key):
211211
return self.remove(key)
212212

213213
def __contains__(self, key):
214-
return hasattr(self.root, key)
214+
""" check for existance of this key
215+
can match the exact pathname or the pathnm w/o the leading '/'
216+
"""
217+
node = self.get_node(key)
218+
if node is not None:
219+
name = node._v_pathname
220+
return re.search(key,name) is not None
221+
return False
215222

216223
def __len__(self):
217224
return len(self.groups())
@@ -228,14 +235,14 @@ def __repr__(self):
228235

229236
keys.append(str(n._v_pathname))
230237

231-
# a group
232-
if kind is None:
233-
values.append('')
234-
235238
# a table
236-
elif _is_table_type(v):
239+
if _is_table_type(n):
237240
values.append(str(create_table(self, n)))
238241

242+
# a group
243+
elif kind is None:
244+
values.append('unknown type')
245+
239246
# another type of pandas object
240247
else:
241248
values.append(_NAME_MAP[kind])
@@ -249,9 +256,9 @@ def __repr__(self):
249256
def keys(self):
250257
"""
251258
Return a (potentially unordered) list of the keys corresponding to the
252-
objects stored in the HDFStore
259+
objects stored in the HDFStore. These are ABSOLUTE path-names (e.g. have the leading '/'
253260
"""
254-
return [ n._v_pathname[1:] for n in self.groups() ]
261+
return [ n._v_pathname for n in self.groups() ]
255262

256263
def open(self, mode='a', warn=True):
257264
"""

pandas/io/tests/test_pytables.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def test_factory_fun(self):
5353

5454
os.remove(self.scratchpath)
5555

56-
def test_len_keys(self):
56+
def test_keys(self):
5757
self.store['a'] = tm.makeTimeSeries()
5858
self.store['b'] = tm.makeStringSeries()
5959
self.store['c'] = tm.makeDataFrame()
6060
self.store['d'] = tm.makePanel()
6161
self.store['foo/bar'] = tm.makePanel()
6262
self.assertEquals(len(self.store), 5)
63-
self.assert_(set(self.store.keys()) == set(['a', 'b', 'c', 'd', 'foo/bar']))
63+
self.assert_(set(self.store.keys()) == set(['/a', '/b', '/c', '/d', '/foo/bar']))
6464

6565
def test_repr(self):
6666
repr(self.store)
@@ -81,6 +81,9 @@ def test_contains(self):
8181
self.assert_('b' in self.store)
8282
self.assert_('c' not in self.store)
8383
self.assert_('foo/bar' in self.store)
84+
self.assert_('/foo/bar' in self.store)
85+
self.assert_('/foo/b' not in self.store)
86+
self.assert_('bar' not in self.store)
8487

8588
def test_reopen_handle(self):
8689
self.store['a'] = tm.makeTimeSeries()

0 commit comments

Comments
 (0)