import pathlib


def pathlib_dir(path):
    """Checks if a path is an existing directory

    Parameters
    ----------
    path: str | pathlib.Path
        File system path to a directory (must exist)
    Returns
    -------
    path: pathlib.Path
        Same path as input coerced to a pathlib.Path object
    Raises
    ------
    ValueError
        If inputted path is not an existing directory
    """
    path = pathlib.Path(path)
    if path.is_dir():
        return path
    raise ValueError("Specified argument is not a valid directory")