Skip to content

Commit 73cb32e

Browse files
dworvosjreback
authored andcommitted
BUG: Presence of softlink in HDF5 file breaks HDFStore.keys() (GH20523) (#20537)
1 parent 6eda77e commit 73cb32e

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
@@ -1098,6 +1098,7 @@ I/O
10981098
- Bug in :func:`read_pickle` when unpickling objects with :class:`TimedeltaIndex` or :class:`Float64Index` created with pandas prior to version 0.20 (:issue:`19939`)
10991099
- Bug in :meth:`pandas.io.json.json_normalize` where subrecords are not properly normalized if any subrecords values are NoneType (:issue:`20030`)
11001100
- Bug in ``usecols`` parameter in :func:`pandas.io.read_csv` and :func:`pandas.io.read_table` where error is not raised correctly when passing a string. (:issue:`20529`)
1101+
- Bug in :func:`HDFStore.keys` when reading a file with a softlink causes exception (:issue:`20523`)
11011102

11021103
Plotting
11031104
^^^^^^^^

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)