def _ensure_groups(handle, path):
    """
    Makes sure a path exists, returning the final group object.

    Parameters
    ----------
    handle : h5py.File
        The file handle in which to ensure the group.
    path : str
        The group to ensure inside the file.
    
    Examples
    --------
    >>> with h5py.File(temp_h5, 'w') as f:
    ...     _ensure_groups(f, '/potato')
    ...     '/potato' in f
    <HDF5 group "/potato" (0 members)>
    True
    """
    group = handle['/']
    heirarchy = path[1:].split('/')
    for name in heirarchy:
        if not name:
            continue
        elif name in group:
            group = group[name]
        else:
            group = group.create_group(name)
    return group
