def read_hdf(path_or_buf, key=None, **kwargs):
    """ read from the store, close it if we opened it

        Retrieve pandas object stored in file, optionally based on where
        criteria

        Parameters
        ----------
        path_or_buf : path (string), or buffer to read from
        key : group identifier in the store. Can be omitted a HDF file contains
            a single pandas object.
        where : list of Term (or convertable) objects, optional
        start : optional, integer (defaults to None), row number to start
            selection
        stop  : optional, integer (defaults to None), row number to stop
            selection
        columns : optional, a list of columns that if not None, will limit the
            return columns
        iterator : optional, boolean, return an iterator, default False
        chunksize : optional, nrows to include in iteration, return an iterator

        Returns
        -------
        The selected object

        """

    # 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, __HOLE__):
            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
dataset/ETHPy150Open pydata/pandas/pandas/io/pytables.py/read_hdf