Skip to content

Commit 8112132

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

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.groups` 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
@@ -5521,3 +5521,20 @@ def test_dst_transitions(self):
55215521
store.append('df', df)
55225522
result = store.select('df')
55235523
assert_frame_equal(result, df)
5524+
5525+
5526+
def test_ignore_hdf_softlink():
5527+
5528+
with ensure_clean_store('tmp.__%s__.h5' % tm.rands(10)) as store:
5529+
5530+
# GH 20523
5531+
# Puts a softlink into HDF file and rereads
5532+
df = DataFrame(dict(A=lrange(5), B=lrange(5)))
5533+
store.put("df", df)
5534+
5535+
assert store.keys() == ["/df"]
5536+
5537+
store._handle.create_soft_link(store._handle.root, "symlink", "df")
5538+
5539+
# Should ignore the softlink
5540+
assert store.keys() == ["/df"]

0 commit comments

Comments
 (0)