diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 4a1b12414bcc5..1ec0e29ae8ce3 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -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 read access + if kwargs.pop('mode', 'r') != 'r': + warnings.warn('Requested write access when calling read_hdf') + # grab the scope if 'where' in kwargs: kwargs['where'] = _ensure_term(kwargs['where'], scope_level=1) @@ -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 diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 66c7ea3cc1236..6ce4f2a8b8fb7 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -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():