import warnings


def ensure_unit(self, name, current_unit, unit, nwb_version):
    """A helper to ensure correct unit used.

    Issues a warning with details if `current_unit` is to be ignored, and
    `unit` to be used instead.
    """
    if current_unit != unit:
        warnings.warn(
            "Unit '%s' for %s '%s' is ignored and will be set to '%s' "
            "as per NWB %s."
            % (current_unit, self.__class__.__name__, name, unit, nwb_version))
    return unit