import warnings


def check_m(m, seasonal):
    """Check the value of M (seasonal periodicity)"""
    if (m < 1 and seasonal) or m < 0:
        raise ValueError('m must be a positive integer (> 0)')

    if not seasonal:
        # default m is 1, so if it's the default, don't warn
        if m > 1:
            warnings.warn("m (%i) set for non-seasonal fit. Setting to 0" % m)
        m = 0

    return m