Exemple #1
0
 def test_period_ordinal_week(self):
     assert period_ordinal(1970, 1, 4, 0, 0, 0, 0, 0, get_freq('W')) == 1
     assert period_ordinal(1970, 1, 5, 0, 0, 0, 0, 0, get_freq('W')) == 2
     assert period_ordinal(2013, 10, 6, 0,
                           0, 0, 0, 0, get_freq('W')) == 2284
     assert period_ordinal(2013, 10, 7, 0,
                           0, 0, 0, 0, get_freq('W')) == 2285
Exemple #2
0
def _range_from_fields(year=None, month=None, quarter=None, day=None,
                       hour=None, minute=None, second=None, freq=None):
    if hour is None:
        hour = 0
    if minute is None:
        minute = 0
    if second is None:
        second = 0
    if day is None:
        day = 1

    ordinals = []

    if quarter is not None:
        if freq is None:
            freq = 'Q'
            base = frequencies.FreqGroup.FR_QTR
        else:
            base, mult = frequencies.get_freq_code(freq)
            if base != frequencies.FreqGroup.FR_QTR:
                raise AssertionError("base must equal FR_QTR")

        year, quarter = _make_field_arrays(year, quarter)
        for y, q in compat.zip(year, quarter):
            y, m = libperiod.quarter_to_myear(y, q, freq)
            val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
            ordinals.append(val)
    else:
        base, mult = frequencies.get_freq_code(freq)
        arrays = _make_field_arrays(year, month, day, hour, minute, second)
        for y, mth, d, h, mn, s in compat.zip(*arrays):
            ordinals.append(libperiod.period_ordinal(
                y, mth, d, h, mn, s, 0, 0, base))

    return np.array(ordinals, dtype=np.int64), freq
Exemple #3
0
 def test_period_ordinal_start_values(self):
     # information for 1.1.1970
     assert period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('A')) == 0
     assert period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('M')) == 0
     assert period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('W')) == 1
     assert period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('D')) == 0
     assert period_ordinal(1970, 1, 1, 0, 0, 0, 0, 0, get_freq('B')) == 0
Exemple #4
0
def _range_from_fields(
    year=None,
    month=None,
    quarter=None,
    day=None,
    hour=None,
    minute=None,
    second=None,
    freq=None,
):
    if hour is None:
        hour = 0
    if minute is None:
        minute = 0
    if second is None:
        second = 0
    if day is None:
        day = 1

    ordinals = []

    if quarter is not None:
        if freq is None:
            freq = to_offset("Q")
            base = FreqGroup.FR_QTR.value
        else:
            freq = to_offset(freq)
            base = libperiod.freq_to_dtype_code(freq)
            if base != FreqGroup.FR_QTR.value:
                raise AssertionError("base must equal FR_QTR")

        freqstr = freq.freqstr
        year, quarter = _make_field_arrays(year, quarter)
        for y, q in zip(year, quarter):
            y, m = parsing.quarter_to_myear(y, q, freqstr)
            val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
            ordinals.append(val)
    else:
        freq = to_offset(freq)
        base = libperiod.freq_to_dtype_code(freq)
        arrays = _make_field_arrays(year, month, day, hour, minute, second)
        for y, mth, d, h, mn, s in zip(*arrays):
            ordinals.append(
                libperiod.period_ordinal(y, mth, d, h, mn, s, 0, 0, base))

    return np.array(ordinals, dtype=np.int64), freq
Exemple #5
0
def _range_from_fields(
    year=None,
    month=None,
    quarter=None,
    day=None,
    hour=None,
    minute=None,
    second=None,
    freq=None,
):
    if hour is None:
        hour = 0
    if minute is None:
        minute = 0
    if second is None:
        second = 0
    if day is None:
        day = 1

    ordinals = []

    if quarter is not None:
        if freq is None:
            freq = "Q"
            base = libfrequencies.FreqGroup.FR_QTR
        else:
            base, mult = libfrequencies.get_freq_code(freq)
            if base != libfrequencies.FreqGroup.FR_QTR:
                raise AssertionError("base must equal FR_QTR")

        year, quarter = _make_field_arrays(year, quarter)
        for y, q in zip(year, quarter):
            y, m = libperiod.quarter_to_myear(y, q, freq)
            val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
            ordinals.append(val)
    else:
        base, mult = libfrequencies.get_freq_code(freq)
        arrays = _make_field_arrays(year, month, day, hour, minute, second)
        for y, mth, d, h, mn, s in zip(*arrays):
            ordinals.append(
                libperiod.period_ordinal(y, mth, d, h, mn, s, 0, 0, base))

    return np.array(ordinals, dtype=np.int64), freq
Exemple #6
0
 def test_period_ordinal_business_day(self):
     # Thursday
     assert period_ordinal(2013, 10, 3, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11415
     # Friday
     assert period_ordinal(2013, 10, 4, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11416
     # Saturday
     assert period_ordinal(2013, 10, 5, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11417
     # Sunday
     assert period_ordinal(2013, 10, 6, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11417
     # Monday
     assert period_ordinal(2013, 10, 7, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11417
     # Tuesday
     assert period_ordinal(2013, 10, 8, 0, 0, 0, 0, 0,
                           get_freq('B')) == 11418
Exemple #7
0
 def test_period_ordinal_business_day(self):
     # Thursday
     assert period_ordinal(2013, 10, 3, 0,
                           0, 0, 0, 0, get_freq('B')) == 11415
     # Friday
     assert period_ordinal(2013, 10, 4, 0,
                           0, 0, 0, 0, get_freq('B')) == 11416
     # Saturday
     assert period_ordinal(2013, 10, 5, 0,
                           0, 0, 0, 0, get_freq('B')) == 11417
     # Sunday
     assert period_ordinal(2013, 10, 6, 0,
                           0, 0, 0, 0, get_freq('B')) == 11417
     # Monday
     assert period_ordinal(2013, 10, 7, 0,
                           0, 0, 0, 0, get_freq('B')) == 11417
     # Tuesday
     assert period_ordinal(2013, 10, 8, 0,
                           0, 0, 0, 0, get_freq('B')) == 11418
def test_period_ordinal_business_day(day, expected):
    args = (2013, 10, day, 0, 0, 0, 0, 0, get_freq("B"))
    assert period_ordinal(*args) == expected
def test_period_ordinal_week(dt, expected):
    args = dt + (get_freq("W"),)
    assert period_ordinal(*args) == expected
def test_period_ordinal_start_values(freq, expected):
    # information for Jan. 1, 1970.
    assert period_ordinal(1970, 1, 1, 0, 0, 0,
                          0, 0, get_freq(freq)) == expected
Exemple #11
0
def test_period_ordinal_business_day(day, expected):
    # 5000 is PeriodDtypeCode for BusinessDay
    args = (2013, 10, day, 0, 0, 0, 0, 0, 5000)
    assert period_ordinal(*args) == expected