def truncate_month(dt, measure):
    """
    Truncate by months

    >>> dt = datetime(2000, 10, 25, 12, 30, 0)
    >>> truncate_month(dt, 1)
    datetime.date(2000, 10, 1)

    >>> truncate_month(dt, 4)
    datetime.date(2000, 8, 1)
    """
    months = dt.year * 12 + dt.month
    months = months // measure * measure
    return date((months - 1) // 12, (months - 1) % 12 + 1, 1)
dataset/ETHPy150Open blaze/blaze/blaze/compute/pydatetime.py/truncate_month/original