Skip to content

BUG: Presence of softlink in HDF5 file breaks HDFStore.keys() (GH20523) #20537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ I/O
- Bug in :func:`read_pickle` when unpickling objects with :class:`TimedeltaIndex` or :class:`Float64Index` created with pandas prior to version 0.20 (:issue:`19939`)
- Bug in :meth:`pandas.io.json.json_normalize` where subrecords are not properly normalized if any subrecords values are NoneType (:issue:`20030`)
- 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`)
- Bug in :func:`HDFStore.keys` when reading a file with a softlink causes exception (:issue:`20523`)

Plotting
^^^^^^^^
Expand Down
7 changes: 4 additions & 3 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,11 @@ def groups(self):
self._check_if_open()
return [
g for g in self._handle.walk_nodes()
if (getattr(g._v_attrs, 'pandas_type', None) or
getattr(g, 'table', None) or
if (not isinstance(g, _table_mod.link.Link) and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other cases we should exclude, or just Link?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link is the abstract base class for SoftLink and ExternalLink in pytables. These subclasses do not support attributes as of HDF5 (this appears to be a limitation of the HDF5 library but may change in the future, reference: http://www.pytables.org/usersguide/libref/link_classes.html). I believe all other node types support attributes. A quick search of NoAttrs in Pytables shows usage only in tables/link.py.

(getattr(g._v_attrs, 'pandas_type', None) or
getattr(g, 'table', None) or
(isinstance(g, _table_mod.table.Table) and
g._v_name != u('table')))
g._v_name != u('table'))))
]

def get_node(self, key):
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,23 @@ def test_keys(self):
assert set(store.keys()) == expected
assert set(store) == expected

def test_keys_ignore_hdf_softlink(self):

# GH 20523
# Puts a softlink into HDF file and rereads

with ensure_clean_store(self.path) as store:

df = DataFrame(dict(A=lrange(5), B=lrange(5)))
store.put("df", df)

assert store.keys() == ["/df"]

store._handle.create_soft_link(store._handle.root, "symlink", "df")

# Should ignore the softlink
assert store.keys() == ["/df"]

def test_iter_empty(self):

with ensure_clean_store(self.path) as store:
Expand Down