Skip to content

Commit 744b046

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

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-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 %s in the file' % key)
1098+
10981099
s = self._create_storer(group)
10991100
s.infer_axes()
11001101
return s

pandas/tests/io/test_pytables.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,8 +3836,13 @@ 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+
pytest.raises(KeyError, store.select_column, 'df', 'index')
3844+
3845+
store.append('df', df)
38413846
# error
38423847
pytest.raises(KeyError, store.select_column, 'df', 'foo')
38433848

0 commit comments

Comments
 (0)