Skip to content

Commit

Permalink
Fixed pandas-dev#16583 by coercing mode to 'r'
Browse files Browse the repository at this point in the history
Adjusted tests on warnings/errors to account for the change
  • Loading branch information
frexvahi committed Jun 6, 2017
1 parent bb8e1da commit 7921b8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ def read_hdf(path_or_buf, key=None, **kwargs):
"""

if kwargs.get('mode', 'a') not in ['r', 'r+', 'a']:
raise ValueError('mode {0} is not allowed while performing a read. '
'Allowed modes are r, r+ and a.'
.format(kwargs.get('mode')))
# Ignore any supplied mode, we only need to read data
if kwargs.pop('mode', 'r') != 'r':
warnings.warn('Ignoring requested mode to read_hdf, opening read-only')

# grab the scope
if 'where' in kwargs:
kwargs['where'] = _ensure_term(kwargs['where'], scope_level=1)
Expand All @@ -343,7 +343,7 @@ def read_hdf(path_or_buf, key=None, **kwargs):
raise compat.FileNotFoundError(
'File %s does not exist' % path_or_buf)

store = HDFStore(path_or_buf, **kwargs)
store = HDFStore(path_or_buf, mode='r', **kwargs)
# can't auto open/close if we are using an iterator
# so delegate to the iterator
auto_close = True
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/io/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ def f():
df.to_hdf(path, 'df', mode=mode)

# conv read
if mode in ['w']:
pytest.raises(ValueError, read_hdf,
path, 'df', mode=mode)
if mode != 'r':
with pytest.warns(UserWarning):
result = read_hdf(path, 'df', mode=mode)
else:
result = read_hdf(path, 'df', mode=mode)
assert_frame_equal(result, df)
assert_frame_equal(result, df)

def check_default_mode():

Expand Down

0 comments on commit 7921b8d

Please sign in to comment.