Skip to content

HDFStore.select_column error reporting #20705

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 3 commits into from
Apr 16, 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 @@ -1111,6 +1111,7 @@ I/O
- 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`)
- Bug in :func:`HDFStore.select_column` where a key which is not a valid store raised an ``AttributeError`` instead of a ``KeyError`` (:issue:`17912`)

Plotting
^^^^^^^^
Expand Down
11 changes: 6 additions & 5 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,10 @@ def remove(self, key, where=None, start=None, stop=None):
where = _ensure_term(where, scope_level=1)
try:
s = self.get_storer(key)
except:
except KeyError:
# the key is not a valid store, re-raising KeyError
raise
except Exception:

if where is not None:
raise ValueError(
Expand All @@ -899,9 +902,6 @@ def remove(self, key, where=None, start=None, stop=None):
s._f_remove(recursive=True)
return None

if s is None:
raise KeyError('No object named %s in the file' % key)

# remove the node
if com._all_none(where, start, stop):
s.group._f_remove(recursive=True)
Expand Down Expand Up @@ -1094,7 +1094,8 @@ def get_storer(self, key):
""" return the storer object for a key, raise if not in the file """
group = self.get_node(key)
if group is None:
return None
raise KeyError('No object named {} in the file'.format(key))

s = self._create_storer(group)
s.infer_axes()
return s
Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3836,8 +3836,15 @@ def test_read_column(self):

with ensure_clean_store(self.path) as store:
_maybe_remove(store, 'df')
store.append('df', df)

# GH 17912
# HDFStore.select_column should raise a KeyError
# exception if the key is not a valid store
with pytest.raises(KeyError,
message='No object named index in the file'):
store.select_column('df', 'index')

store.append('df', df)
# error
pytest.raises(KeyError, store.select_column, 'df', 'foo')

Expand Down