Skip to content

Commit 80033c7

Browse files
author
Andrew Bui
committed
BUG: Presence of softlink in HDF5 file breaks HDFStore.keys() (GH20523)
1 parent f00e149 commit 80033c7

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ I/O
10201020
- Bug in :meth:`pandas.io.stata.StataReader.value_labels` raising an ``AttributeError`` when called on very old files. Now returns an empty dict (:issue:`19417`)
10211021
- Bug in :func:`read_pickle` when unpickling objects with :class:`TimedeltaIndex` or :class:`Float64Index` created with pandas prior to version 0.20 (:issue:`19939`)
10221022
- Bug in :meth:`pandas.io.json.json_normalize` where subrecords are not properly normalized if any subrecords values are NoneType (:issue:`20030`)
1023+
- Bug in :func:`HDFStore.keys` when reading a file with a softlink causes exception (:issue:`20523`)
10231024

10241025
Plotting
10251026
^^^^^^^^

pandas/io/pytables.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,11 @@ def groups(self):
10731073
self._check_if_open()
10741074
return [
10751075
g for g in self._handle.walk_nodes()
1076-
if (getattr(g._v_attrs, 'pandas_type', None) or
1077-
getattr(g, 'table', None) or
1076+
if (not isinstance(g, _table_mod.link.Link) and
1077+
(getattr(g._v_attrs, 'pandas_type', None) or
1078+
getattr(g, 'table', None) or
10781079
(isinstance(g, _table_mod.table.Table) and
1079-
g._v_name != u('table')))
1080+
g._v_name != u('table'))))
10801081
]
10811082

10821083
def get_node(self, key):

pandas/tests/io/test_pytables.py

+17
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,23 @@ def test_keys(self):
373373
assert set(store.keys()) == expected
374374
assert set(store) == expected
375375

376+
def test_keys_ignore_hdf_softlink(self):
377+
378+
# GH 20523
379+
# Puts a softlink into HDF file and rereads
380+
381+
with ensure_clean_store(self.path) as store:
382+
383+
df = DataFrame(dict(A=lrange(5), B=lrange(5)))
384+
store.put("df", df)
385+
386+
assert store.keys() == ["/df"]
387+
388+
store._handle.create_soft_link(store._handle.root, "symlink", "df")
389+
390+
# Should ignore the softlink
391+
assert store.keys() == ["/df"]
392+
376393
def test_iter_empty(self):
377394

378395
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)