Convert from NumPy dtype to Weld type.

    Note that support for strings is intended to be only for
    Python 2 str and Python 3 bytes. No unicode.

    Parameters
    ----------
    np_dtype : numpy.dtype or str
        NumPy dtype.

    Returns
    -------
    WeldType
        Corresponding WeldType.

    Examples
    --------
    >>> import numpy as np
    >>> from baloo.weld import numpy_to_weld_type
    >>> str(numpy_to_weld_type(np.dtype(np.int64)))
    'i64'
    >>> str(numpy_to_weld_type('?'))
    'bool'

def numpy_to_weld_type(np_dtype):
    """Convert from NumPy dtype to Weld type.

    Note that support for strings is intended to be only for
    Python 2 str and Python 3 bytes. No unicode.

    Parameters
    ----------
    np_dtype : numpy.dtype or str
        NumPy dtype.

    Returns
    -------
    WeldType
        Corresponding WeldType.

    Examples
    --------
    >>> import numpy as np
    >>> from baloo.weld import numpy_to_weld_type
    >>> str(numpy_to_weld_type(np.dtype(np.int64)))
    'i64'
    >>> str(numpy_to_weld_type('?'))
    'bool'

    """
    if not isinstance(np_dtype, (str, bytes, np.dtype, type)):
        raise TypeError('Can only convert np.dtype or str')

    if isinstance(np_dtype, (str, bytes, type)):
        np_dtype = np.dtype(np_dtype)

    return _numpy_to_weld_type_mapping[np_dtype.char]