import multiprocessing


def _check_n_jobs(n_jobs):
    """Check n_jobs in particular for negative values

    Parameters
    ----------
    n_jobs : int
        The number of jobs.

    Returns
    -------
    n_jobs : int
        The checked number of jobs. Always positive.
    """
    if not isinstance(n_jobs, int):
        raise TypeError('n_jobs must be an integer')
    if n_jobs <= 0:
        n_cores = multiprocessing.cpu_count()
        n_jobs = max(min(n_cores + n_jobs + 1, n_cores), 1)
    return n_jobs