import six


def pds_to_numpy_name(name):
    """ Create a NumPy field name from a PDS4 field name.

    Parameters
    ----------
    name : str or unicode
        A PDS4 field name.

    Returns
    -------
    str
        A NumPy-compliant field name.
    """

    # We encode to UTF-8 because under Python 2 NumPy does not accept unicode. We replace
    # the colon by an underscore because under Python 3 this seems to cause an error when using
    # ``recarray.__new__`` with the ``buf`` keyword.

    name = name.replace(':', '_')
    if six.PY2:
        name = name.encode('utf-8')

    return name