def _raise_error_if_not_function(arg, arg_name=None):
    """
    Check if the input is of expected type.

    Parameters
    ----------
    arg            : Input argument.

    arg_name      : The name of the variable in the function being used. No
                    name is assumed if set to None.

    Examples
    --------
    _raise_error_if_not_function(func, 'func')

    """
    display_name = '%s ' % arg_name if arg_name is not None else ''
    err_msg = 'Argument %smust be a function.' % display_name
    if not hasattr(arg, '__call__'):
        raise TypeError(err_msg)
