def read_hdf(path_or_buf, key=None, mode='<STR_LIT:r>', **kwargs):
if mode not in ['<STR_LIT:r>', '<STR_LIT>', '<STR_LIT:a>']:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(mode))<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>kwargs['<STR_LIT>'] = _ensure_term(kwargs['<STR_LIT>'], scope_level=<NUM_LIT:1>)<EOL><DEDENT>if isinstance(path_or_buf, HDFStore):<EOL><INDENT>if not path_or_buf.is_open:<EOL><INDENT>raise IOError('<STR_LIT>')<EOL><DEDENT>store = path_or_buf<EOL>auto_close = False<EOL><DEDENT>else:<EOL><INDENT>path_or_buf = _stringify_path(path_or_buf)<EOL>if not isinstance(path_or_buf, str):<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>exists = os.path.exists(path_or_buf)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>exists = False<EOL><DEDENT>if not exists:<EOL><INDENT>raise FileNotFoundError(<EOL>'<STR_LIT>'.format(path=path_or_buf))<EOL><DEDENT>store = HDFStore(path_or_buf, mode=mode, **kwargs)<EOL>auto_close = True<EOL><DEDENT>try:<EOL><INDENT>if key is None:<EOL><INDENT>groups = store.groups()<EOL>if len(groups) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>candidate_only_group = groups[<NUM_LIT:0>]<EOL>for group_to_check in groups[<NUM_LIT:1>:]:<EOL><INDENT>if not _is_metadata_of(group_to_check, candidate_only_group):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>key = candidate_only_group._v_pathname<EOL><DEDENT>return store.select(key, auto_close=auto_close, **kwargs)<EOL><DEDENT>except (ValueError, TypeError, KeyError):<EOL><INDENT>try:<EOL><INDENT>store.close()<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>raise<EOL><DEDENT>
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 : string, buffer or path object
    Path to the file to open, or an open :class:`pandas.HDFStore` object.
    Supports any object implementing the ``__fspath__`` protocol.
    This includes :class:`pathlib.Path` and py._path.local.LocalPath
    objects.

    .. versionadded:: 0.19.0 support for pathlib, py.path.
    .. versionadded:: 0.21.0 support for __fspath__ protocol.

key : object, optional
    The group identifier in the store. Can be omitted if the HDF file
    contains a single pandas object.
mode : {'r', 'r+', 'a'}, optional
    Mode to use when opening the file. Ignored if path_or_buf is a
    :class:`pandas.HDFStore`. Default is 'r'.
where : list, optional
    A list of Term (or convertible) objects.
start : int, optional
    Row number to start selection.
stop  : int, optional
    Row number to stop selection.
columns : list, optional
    A list of columns names to return.
iterator : bool, optional
    Return an iterator object.
chunksize : int, optional
    Number of rows to include in an iteration when using an iterator.
errors : str, default 'strict'
    Specifies how encoding and decoding errors are to be handled.
    See the errors argument for :func:`open` for a full list
    of options.
**kwargs
    Additional keyword arguments passed to HDFStore.

Returns
-------
item : object
    The selected object. Return type depends on the object stored.

See Also
--------
DataFrame.to_hdf : Write a HDF file from a DataFrame.
HDFStore : Low-level access to HDF files.

Examples
--------
>>> df = pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])
>>> df.to_hdf('./store.h5', 'data')
>>> reread = pd.read_hdf('./store.h5')