def read_hdf(path_or_buf, key=None, **kwargs):

    # grab the scope
    if 'where' in kwargs:
        kwargs['where'] = _ensure_term(kwargs['where'], scope_level=1)

    if isinstance(path_or_buf, string_types):

        try:
            exists = os.path.exists(path_or_buf)

        # if filepath is too long
        except (TypeError, ValueError):
            exists = False

        if not exists:
            raise IOError('File %s does not exist' % path_or_buf)

        # can't auto open/close if we are using an iterator
        # so delegate to the iterator
        store = HDFStore(path_or_buf, **kwargs)
        auto_close = True

    elif isinstance(path_or_buf, HDFStore):
        if not path_or_buf.is_open:
            raise IOError('The HDFStore must be open for reading.')

        store = path_or_buf
        auto_close = False
    else:
        raise NotImplementedError('Support for generic buffers has not been '
                                  'implemented.')

    try:
        if key is None:
            keys = store.keys()
            if len(keys) != 1:
                raise ValueError('key must be provided when HDF file contains '
                                 'multiple datasets.')
            key = keys[0]
        return store.select(key, auto_close=auto_close, **kwargs)
    except:
        # if there is an error, close the store
        try:
            store.close()
        except:
            pass

        raise
read from the store, close it if we opened it
dataset/ETHPy150Open pydata/pandas/pandas/io/pytables.py/read_hdf