Repository: pandas-dev/pandas

Issue:
read_hdf() requires write permission
read_hdf() called get_store() with default open mode, which is 'a', and so requires write permissions to read a file. Please change to 'r'.



Discussion:
you can pass `mode='r'` to `read_hdf` (and `get_store` and `open` and the `HDFStore()`) if you would like, the default has been like this for quite a long time and would break back compat.

to get_store(), etc., but unfortunately not to read_hdf() (as of 0.11.0, anyway)

yes you are right! wll mark as a bug for 0.13, you can monkey patch if you want to fix your copy...

Yep. Thanks.


Resolving patch:
diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py
--- a/pandas/io/pytables.py
+++ b/pandas/io/pytables.py
@@ -167,8 +167,7 @@ def h5_open(path, mode):
 
 
 @contextmanager
-def get_store(path, mode='a', complevel=None, complib=None,
-              fletcher32=False):
+def get_store(path, **kwargs):
     """
     Creates an HDFStore instance. This function can be used in a with statement
 
@@ -184,8 +183,7 @@ def get_store(path, mode='a', complevel=None, complib=None,
     """
     store = None
     try:
-        store = HDFStore(path, mode=mode, complevel=complevel,
-                         complib=complib, fletcher32=False)
+        store = HDFStore(path, **kwargs)
         yield store
     finally:
         if store is not None:
@@ -215,7 +213,7 @@ def read_hdf(path_or_buf, key, **kwargs):
 
         # can't auto open/close if we are using an iterator
         # so delegate to the iterator
-        store = HDFStore(path_or_buf)
+        store = HDFStore(path_or_buf,**kwargs)
         try:
             return f(store, True)
         except:
@@ -274,7 +272,7 @@ class HDFStore(StringMixin):
     """
 
     def __init__(self, path, mode=None, complevel=None, complib=None,
-                 fletcher32=False):
+                 fletcher32=False, **kwargs):
         try:
             import tables as _
         except ImportError:  # pragma: no cover


Test patch:
diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py
--- a/pandas/io/tests/test_pytables.py
+++ b/pandas/io/tests/test_pytables.py
@@ -234,6 +234,56 @@ def test_versioning(self):
             store.get_node('df2')._v_attrs.pandas_version = None
             self.assertRaises(Exception, store.select, 'df2')
 
+    def test_mode(self):
+
+        df = tm.makeTimeDataFrame()
+
+        def check(mode):
+
+            with tm.ensure_clean(self.path) as path:
+
+                # constructor
+                if mode in ['r','r+']:
+                    self.assertRaises(IOError, HDFStore, path, mode=mode)
+
+                else:
+                    store = HDFStore(path,mode=mode)
+                    self.assert_(store._handle.mode == mode)
+                    store.close()
+
+            with tm.ensure_clean(self.path) as path:
+
+                # context
+                if mode in ['r','r+']:
+                    def f():
+                        with get_store(path,mode=mode) as store:
+                            pass
+                    self.assertRaises(IOError, f)
+                else:
+                    with get_store(path,mode=mode) as store:
+                        self.assert_(store._handle.mode == mode)
+
+            with tm.ensure_clean(self.path) as path:
+
+                # conv write
+                if mode in ['r','r+']:
+                    self.assertRaises(IOError, df.to_hdf, path, 'df', mode=mode)
+                    df.to_hdf(path,'df',mode='w')
+                else:
+                    df.to_hdf(path,'df',mode=mode)
+
+                # conv read
+                if mode in ['w']:
+                    self.assertRaises(KeyError, read_hdf, path, 'df', mode=mode)
+                else:
+                    result = read_hdf(path,'df',mode=mode)
+                    assert_frame_equal(result,df)
+
+        check('r')
+        check('r+')
+        check('a')
+        check('w')
+
     def test_reopen_handle(self):
 
         with tm.ensure_clean(self.path) as path: