Skip to content

Commit 10f511c

Browse files
committed
BUG: make HDFStore.select_column raise a KeyError when key is not a valid store
1 parent d5d5a71 commit 10f511c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pandas/io/pytables.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ def get_storer(self, key):
10941094
""" return the storer object for a key, raise if not in the file """
10951095
group = self.get_node(key)
10961096
if group is None:
1097-
return None
1097+
raise KeyError('No object named {} in the file'.format(key))
1098+
10981099
s = self._create_storer(group)
10991100
s.infer_axes()
11001101
return s

pandas/tests/io/test_pytables.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,8 +3836,14 @@ def test_read_column(self):
38363836

38373837
with ensure_clean_store(self.path) as store:
38383838
_maybe_remove(store, 'df')
3839-
store.append('df', df)
38403839

3840+
# GH 17912
3841+
# HDFStore.select_column should raise a KeyError
3842+
# exception if the key is not a valid store
3843+
with pytest.raises(KeyError, message='No object named index in the file'):
3844+
store.select_column('df', 'index')
3845+
3846+
store.append('df', df)
38413847
# error
38423848
pytest.raises(KeyError, store.select_column, 'df', 'foo')
38433849

0 commit comments

Comments
 (0)