Beispiel #1
0
    def test_construction(self):
        i1 = Period('1/1/2005', freq='M')
        i2 = Period('Jan 2005')

        assert i1 == i2

        i1 = Period('2005', freq='A')
        i2 = Period('2005')
        i3 = Period('2005', freq='a')

        assert i1 == i2
        assert i1 == i3

        i4 = Period('2005', freq='M')
        i5 = Period('2005', freq='m')

        pytest.raises(ValueError, i1.__ne__, i4)
        assert i4 == i5

        i1 = Period.now('Q')
        i2 = Period(datetime.now(), freq='Q')
        i3 = Period.now('q')

        assert i1 == i2
        assert i1 == i3

        i1 = Period('1982', freq='min')
        i2 = Period('1982', freq='MIN')
        assert i1 == i2
        i2 = Period('1982', freq=('Min', 1))
        assert i1 == i2

        i1 = Period(year=2005, month=3, day=1, freq='D')
        i2 = Period('3/1/2005', freq='D')
        assert i1 == i2

        i3 = Period(year=2005, month=3, day=1, freq='d')
        assert i1 == i3

        i1 = Period('2007-01-01 09:00:00.001')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq='L')
        assert i1 == expected

        expected = Period(np_datetime64_compat(
            '2007-01-01 09:00:00.001Z'), freq='L')
        assert i1 == expected

        i1 = Period('2007-01-01 09:00:00.00101')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq='U')
        assert i1 == expected

        expected = Period(np_datetime64_compat('2007-01-01 09:00:00.00101Z'),
                          freq='U')
        assert i1 == expected

        pytest.raises(ValueError, Period, ordinal=200701)

        pytest.raises(ValueError, Period, '2007-1-1', freq='X')
Beispiel #2
0
    def test_construction(self):
        i1 = Period('1/1/2005', freq='M')
        i2 = Period('Jan 2005')

        assert i1 == i2

        i1 = Period('2005', freq='A')
        i2 = Period('2005')
        i3 = Period('2005', freq='a')

        assert i1 == i2
        assert i1 == i3

        i4 = Period('2005', freq='M')
        i5 = Period('2005', freq='m')

        pytest.raises(ValueError, i1.__ne__, i4)
        assert i4 == i5

        i1 = Period.now('Q')
        i2 = Period(datetime.now(), freq='Q')
        i3 = Period.now('q')

        assert i1 == i2
        assert i1 == i3

        i1 = Period('1982', freq='min')
        i2 = Period('1982', freq='MIN')
        assert i1 == i2
        i2 = Period('1982', freq=('Min', 1))
        assert i1 == i2

        i1 = Period(year=2005, month=3, day=1, freq='D')
        i2 = Period('3/1/2005', freq='D')
        assert i1 == i2

        i3 = Period(year=2005, month=3, day=1, freq='d')
        assert i1 == i3

        i1 = Period('2007-01-01 09:00:00.001')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq='L')
        assert i1 == expected

        expected = Period(np_datetime64_compat(
            '2007-01-01 09:00:00.001Z'), freq='L')
        assert i1 == expected

        i1 = Period('2007-01-01 09:00:00.00101')
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq='U')
        assert i1 == expected

        expected = Period(np_datetime64_compat('2007-01-01 09:00:00.00101Z'),
                          freq='U')
        assert i1 == expected

        pytest.raises(ValueError, Period, ordinal=200701)

        pytest.raises(ValueError, Period, '2007-1-1', freq='X')
Beispiel #3
0
class Properties(object):
    def setup(self):
        self.per = Period('2017-09-06 08:28', freq='min')

    def time_year(self):
        self.per.year

    def time_month(self):
        self.per.month

    def time_day(self):
        self.per.day

    def time_hour(self):
        self.per.hour

    def time_minute(self):
        self.per.minute

    def time_second(self):
        self.per.second

    def time_is_leap_year(self):
        self.per.is_leap_year

    def time_quarter(self):
        self.per.quarter

    def time_qyear(self):
        self.per.qyear

    def time_week(self):
        self.per.week

    def time_daysinmonth(self):
        self.per.daysinmonth

    def time_dayofweek(self):
        self.per.dayofweek

    def time_dayofyear(self):
        self.per.dayofyear

    def time_start_time(self):
        self.per.start_time

    def time_end_time(self):
        self.per.end_time

    def time_to_timestamp():
        self.per.to_timestamp()

    def time_now():
        self.per.now()

    def time_asfreq():
        self.per.asfreq('A')
Beispiel #4
0
class Properties(object):
    def setup(self):
        self.per = Period('2017-09-06 08:28', freq='min')

    def time_year(self):
        self.per.year

    def time_month(self):
        self.per.month

    def time_day(self):
        self.per.day

    def time_hour(self):
        self.per.hour

    def time_minute(self):
        self.per.minute

    def time_second(self):
        self.per.second

    def time_is_leap_year(self):
        self.per.is_leap_year

    def time_quarter(self):
        self.per.quarter

    def time_qyear(self):
        self.per.qyear

    def time_week(self):
        self.per.week

    def time_daysinmonth(self):
        self.per.daysinmonth

    def time_dayofweek(self):
        self.per.dayofweek

    def time_dayofyear(self):
        self.per.dayofyear

    def time_start_time(self):
        self.per.start_time

    def time_end_time(self):
        self.per.end_time

    def time_to_timestamp():
        self.per.to_timestamp()

    def time_now():
        self.per.now()

    def time_asfreq():
        self.per.asfreq('A')
Beispiel #5
0
class PeriodUnaryMethods(object):
    params = ['M', 'min']
    param_names = ['freq']

    def setup(self, freq):
        self.per = Period('2012-06-01', freq=freq)

    def time_to_timestamp(self, freq):
        self.per.to_timestamp()

    def time_now(self, freq):
        self.per.now(freq)

    def time_asfreq(self, freq):
        self.per.asfreq('A')
Beispiel #6
0
class PeriodUnaryMethods(object):
    params = ['M', 'min']
    param_names = ['freq']

    def setup(self, freq):
        self.per = Period('2012-06-01', freq=freq)

    def time_to_timestamp(self, freq):
        self.per.to_timestamp()

    def time_now(self, freq):
        self.per.now(freq)

    def time_asfreq(self, freq):
        self.per.asfreq('A')
Beispiel #7
0
class PeriodUnaryMethods:

    params = ["M", "min"]
    param_names = ["freq"]

    def setup(self, freq):
        self.per = Period("2012-06-01", freq=freq)

    def time_to_timestamp(self, freq):
        self.per.to_timestamp()

    def time_now(self, freq):
        self.per.now(freq)

    def time_asfreq(self, freq):
        self.per.asfreq("A")
def get_loan_rate(loan_type, report_period=None):
    
    logger.debug('loan_type=%s, report_period=%s', loan_type, report_period)

    if report_period is None:
        report_period = Period.now('D')   
    elif isinstance(report_period, str):
        report_period = Period(report_period)
    
    loan_rates = ts.get_loan_rate()
    loan_rates = loan_rates.sort_values(by=['date'])
    
    loan_rates = loan_rates.loc[loan_rates['loan_type'] == loan_type, ['date', 'rate']]
    
    logger.debug('loan_rates.values=\n%s', loan_rates.values)
    
    loan_rate = None
    for record in loan_rates.values:
        rate_date = Period(record[0])
        if rate_date <= report_period and record[1] != '--':
            loan_rate = float(record[1]) / 100

    logger.debug('loan_rate=%f', loan_rate)
    return loan_rate
Beispiel #9
0
    def test_construction(self):
        i1 = Period("1/1/2005", freq="M")
        i2 = Period("Jan 2005")

        assert i1 == i2

        i1 = Period("2005", freq="A")
        i2 = Period("2005")
        i3 = Period("2005", freq="a")

        assert i1 == i2
        assert i1 == i3

        i4 = Period("2005", freq="M")
        i5 = Period("2005", freq="m")

        msg = r"Input has different freq=M from Period\(freq=A-DEC\)"
        with pytest.raises(IncompatibleFrequency, match=msg):
            i1 != i4
        assert i4 == i5

        i1 = Period.now("Q")
        i2 = Period(datetime.now(), freq="Q")
        i3 = Period.now("q")

        assert i1 == i2
        assert i1 == i3

        i1 = Period("1982", freq="min")
        i2 = Period("1982", freq="MIN")
        assert i1 == i2
        i2 = Period("1982", freq=("Min", 1))
        assert i1 == i2

        i1 = Period(year=2005, month=3, day=1, freq="D")
        i2 = Period("3/1/2005", freq="D")
        assert i1 == i2

        i3 = Period(year=2005, month=3, day=1, freq="d")
        assert i1 == i3

        i1 = Period("2007-01-01 09:00:00.001")
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq="L")
        assert i1 == expected

        expected = Period(np_datetime64_compat("2007-01-01 09:00:00.001Z"), freq="L")
        assert i1 == expected

        i1 = Period("2007-01-01 09:00:00.00101")
        expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq="U")
        assert i1 == expected

        expected = Period(np_datetime64_compat("2007-01-01 09:00:00.00101Z"), freq="U")
        assert i1 == expected

        msg = "Must supply freq for ordinal value"
        with pytest.raises(ValueError, match=msg):
            Period(ordinal=200701)

        msg = "Invalid frequency: X"
        with pytest.raises(ValueError, match=msg):
            Period("2007-1-1", freq="X")