Repository: dask/dask

Issue:
Error with read_hdf
Hello,
I'm trying to read back an hdf5 file written out with dask and I'm getting the following error:

``` python
import dask.dataframe as ddf
import pandas as pd
from pandas import *

my_ddf = ddf.from_pandas( factor_df, 3)
my_ddf.to_hdf( LOCAL_DATA_PATH+'/testhdf4.h5', key='factor_df', mode='w', format='fixed' )
my_ddf2 = ddf.read_hdf( LOCAL_DATA_PATH+'/testhdf4.h5', key='factor_df' )
```

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-89ec51417fb9> in <module>()
----> 1 my_ddf2 = ddf.read_hdf(LOCAL_DATA_PATH+'/testhdf4.h5', key='factor_df')

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in read_hdf(pattern, key, start, stop, columns, chunksize, lock)
    726                                     columns=columns, chunksize=chunksize,
    727                                     lock=lock)
--> 728                    for path in paths])
    729 
    730 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in <listcomp>(.0)
    726                                     columns=columns, chunksize=chunksize,
    727                                     lock=lock)
--> 728                    for path in paths])
    729 
    730 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in _read_single_hdf(path, key, start, stop, columns, chunksize, lock)
    667     from .multi import concat
    668     return concat([one_path_one_key(path, k, start, s, columns, chunksize, lock)
--> 669                    for k, s in zip(keys, stops)])
    670 
    671 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/multi.py in concat(dfs, axis, join, interleave_partitions)
    504         dfs = [dfs]
    505     if len(dfs) == 0:
--> 506         raise ValueError('Input must be a list longer than 0')
    507     if len(dfs) == 1:
    508         return dfs[0]

ValueError: Input must be a list longer than 0
```

The hdf5 file can be read back without any problem using pandas HDFStore function:

``` python
HDFStore(LOCAL_DATA_PATH+'/testhdf4.h5').get('factor_df')
```

![image](https://cloud.githubusercontent.com/assets/923438/11513633/44fb92d4-9842-11e5-872b-c255f9b802aa.png)



Discussion:
Hi @fjanoos can you provide a sample dataset that I can use to reproduce this error locally?

@mrocklin 

This code gives rise to the same problem : 

``` python
from pylab import *
import dask.dataframe as ddf
import pandas as pd
from pandas import *

my_df = DataFrame( randn(1000,1000))

my_ddf = ddf.from_pandas(my_df, 3)
my_ddf.to_hdf(LOCAL_DATA_PATH+'/testhdf4.h5', key='my_df', mode='a', format='table', append=True)

my_ddf2 = ddf.read_hdf(LOCAL_DATA_PATH+'/testhdf4.h5', key='my_df')
```

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-39-edcc5f95853e> in <module>()
----> 1 my_ddf2 = ddf.read_hdf(LOCAL_DATA_PATH+'/testhdf4.h5', key='my_df')

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in read_hdf(pattern, key, start, stop, columns, chunksize, lock)
    726                                     columns=columns, chunksize=chunksize,
    727                                     lock=lock)
--> 728                    for path in paths])
    729 
    730 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in <listcomp>(.0)
    726                                     columns=columns, chunksize=chunksize,
    727                                     lock=lock)
--> 728                    for path in paths])
    729 
    730 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/io.py in _read_single_hdf(path, key, start, stop, columns, chunksize, lock)
    667     from .multi import concat
    668     return concat([one_path_one_key(path, k, start, s, columns, chunksize, lock)
--> 669                    for k, s in zip(keys, stops)])
    670 
    671 

/home/firdaus/local/software/anaconda/lib/python3.4/site-packages/dask-0.7.4-py3.4.egg/dask/dataframe/multi.py in concat(dfs, axis, join, interleave_partitions)
    504         dfs = [dfs]
    505     if len(dfs) == 0:
--> 506         raise ValueError('Input must be a list longer than 0')
    507     if len(dfs) == 1:
    508         return dfs[0]

ValueError: Input must be a list longer than 0
```

Even this write function causes the same error in reading:

```
my_ddf.to_hdf(LOCAL_DATA_PATH+'/testhdf4.h5', key='my_df', mode='w', format='fixed')
```

Regarding my setup, I'm using:

3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Oct 19 2015, 21:52:17) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

dask: 0.7.4

Linux Debian 3.16.7


Resolving patch:
diff --git a/dask/dataframe/io.py b/dask/dataframe/io.py
--- a/dask/dataframe/io.py
+++ b/dask/dataframe/io.py
@@ -709,6 +709,7 @@ def read_hdf(pattern, key, start=0, stop=None, columns=None,
 
     >>> dd.read_hdf('myfile.1.hdf5', '/*')  # doctest: +SKIP
     """
+    key = key if key.startswith('/')  else '/' + key
     paths = sorted(glob(pattern))
     if (start != 0 or stop is not None) and len(paths) > 1:
         raise NotImplementedError(read_hdf_error_msg)


Test patch:
diff --git a/dask/dataframe/tests/test_io.py b/dask/dataframe/tests/test_io.py
--- a/dask/dataframe/tests/test_io.py
+++ b/dask/dataframe/tests/test_io.py
@@ -516,7 +516,7 @@ def test_read_hdf():
     with tmpfile('h5') as fn:
         df.to_hdf(fn, '/data')
         try:
-            dd.read_hdf(fn, '/data', chunksize=2)
+            dd.read_hdf(fn, 'data', chunksize=2)
             assert False
         except TypeError as e:
             assert "format='table'" in str(e)