Skip to content

Commit 74940d7

Browse files
committed
export enums
1 parent f432d0f commit 74940d7

File tree

3 files changed

+75
-104
lines changed

3 files changed

+75
-104
lines changed

quantlib/time/_date.pxd

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from quantlib.types cimport *
22

3-
cdef extern from 'ql/time/date.hpp' namespace 'QuantLib':
3+
cdef extern from 'ql/time/date.hpp' namespace 'QuantLib' nogil:
44
ctypedef int Year
55
ctypedef int Day
66
ctypedef int Hour
@@ -18,25 +18,12 @@ cdef extern from "ostream" namespace "std":
1818
cdef cppclass ostream:
1919
pass
2020

21-
cdef extern from 'ql/time/weekday.hpp' namespace "QuantLib":
21+
cdef extern from 'ql/time/weekday.hpp' namespace "QuantLib" nogil:
2222

2323
cdef enum Weekday:
24-
Sunday = 1
25-
Monday = 2
26-
Tuesday = 3
27-
Wednesday = 4
28-
Thursday = 5
29-
Friday = 6
30-
Saturday = 7
31-
Sun = 1
32-
Mon = 2
33-
Tue = 3
34-
Wed = 4
35-
Thu = 5
36-
Fri = 6
37-
Sat = 7
38-
39-
cdef extern from "ql/time/date.hpp" namespace "QuantLib::Date":
24+
pass
25+
26+
cdef extern from "ql/time/date.hpp" namespace "QuantLib::Date" nogil:
4027
ctypedef int_fast32_t serial_type
4128
cdef Date todaysDate()
4229
cdef Date minDate()
@@ -50,35 +37,14 @@ cdef extern from "ql/time/date.hpp" namespace "QuantLib::Date":
5037
cdef Date localDateTime()
5138
cdef Date universalDateTime()
5239

53-
cdef extern from "ql/time/date.hpp" namespace "QuantLib":
40+
41+
cdef extern from "ql/time/date.hpp" namespace "QuantLib" nogil:
5442

5543
cdef enum Month:
56-
January = 1
57-
February = 2
58-
March = 3
59-
April = 4
60-
May = 5
61-
June = 6
62-
July = 7
63-
August = 8
64-
September = 9
65-
October = 10
66-
November = 11
67-
December = 12
68-
Jan = 1
69-
Feb = 2
70-
Mar = 3
71-
Apr = 4
72-
Jun = 6
73-
Jul = 7
74-
Aug = 8
75-
Sep = 9
76-
Oct = 10
77-
Nov = 11
78-
Dec = 12
44+
pass
7945

8046
cdef cppclass Date:
81-
Date() except +
47+
Date()
8248
Date(serial_type serialnumber) except +
8349
Date(const Date&)
8450
Date(Day d, Month m, Year y) except +
@@ -134,13 +100,13 @@ cdef extern from "ql/time/date.hpp" namespace "QuantLib::detail":
134100
cdef cppclass formatted_date_holder:
135101
pass
136102

137-
cdef extern from "ql/time/date.hpp" namespace "QuantLib::io":
103+
cdef extern from "ql/time/date.hpp" namespace "QuantLib::io" nogil:
138104
cdef short_date_holder short_date(const Date&)
139105
cdef iso_date_holder iso_date(const Date&)
140106
cdef iso_datetime_holder iso_datetime(const Date&)
141107
cdef formatted_date_holder formatted_date(const Date&, const string& fmt)
142108

143-
cdef extern from "<sstream>" namespace "std":
109+
cdef extern from "<sstream>" namespace "std" nogil:
144110
cdef cppclass stringstream:
145111
stringstream& operator<<(iso_date_holder)
146112
stringstream& operator<<(short_date_holder)
@@ -149,6 +115,6 @@ cdef extern from "<sstream>" namespace "std":
149115
stringstream& operator<<(formatted_date_holder)
150116
string str()
151117

152-
cdef extern from 'ql/utilities/dataparsers.hpp' namespace "QuantLib::DateParser":
118+
cdef extern from 'ql/utilities/dataparsers.hpp' namespace "QuantLib::DateParser" nogil:
153119
Date parseISO(const string& str) except +
154120
Date parseFormatted(const string&, const string&) except +

quantlib/time/date.pxd

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,71 @@
1-
"""
2-
Copyright (C) 2011, Enthought Inc
3-
Copyright (C) 2011, Patrick Henaff
1+
# Copyright (C) 2011, Enthought Inc
2+
# Copyright (C) 2011, Patrick Henaff
3+
4+
# This program is distributed in the hope that it will be useful, but WITHOUT
5+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
6+
# FOR A PARTICULAR PURPOSE. See the license for more details.
47

5-
This program is distributed in the hope that it will be useful, but WITHOUT
6-
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7-
FOR A PARTICULAR PURPOSE. See the license for more details.
8-
"""
98

109
from libcpp cimport bool
11-
cimport quantlib.time._date as _date
10+
from ._date cimport Date as QlDate
11+
1212
cimport quantlib.time._period as _period
1313
from quantlib.handle cimport shared_ptr
1414

15+
cdef extern from 'ql/time/weekday.hpp' namespace "QuantLib" nogil:
16+
17+
cpdef enum Weekday:
18+
Sunday = 1
19+
Monday = 2
20+
Tuesday = 3
21+
Wednesday = 4
22+
Thursday = 5
23+
Friday = 6
24+
Saturday = 7
25+
Sun = 1
26+
Mon = 2
27+
Tue = 3
28+
Wed = 4
29+
Thu = 5
30+
Fri = 6
31+
Sat = 7
32+
33+
cdef extern from "ql/time/date.hpp" namespace "QuantLib" nogil:
34+
35+
cpdef enum Month:
36+
January = 1
37+
February = 2
38+
March = 3
39+
April = 4
40+
May = 5
41+
June = 6
42+
July = 7
43+
August = 8
44+
September = 9
45+
October = 10
46+
November = 11
47+
December = 12
48+
Jan = 1
49+
Feb = 2
50+
Mar = 3
51+
Apr = 4
52+
Jun = 6
53+
Jul = 7
54+
Aug = 8
55+
Sep = 9
56+
Oct = 10
57+
Nov = 11
58+
Dec = 12
59+
60+
1561
cdef class Period:
1662
cdef shared_ptr[_period.Period] _thisptr
1763

1864
cdef class Date:
19-
cdef _date.Date _thisptr
65+
cdef QlDate _thisptr
2066

21-
cdef Date date_from_qldate(const _date.Date& date)
67+
cdef Date date_from_qldate(const QlDate& date)
2268
cdef Period period_from_qlperiod(const _period.Period& period)
2369

24-
cdef object _pydate_from_qldate(_date.Date qdate)
25-
cdef _date.Date _qldate_from_pydate(object date)
70+
cdef object _pydate_from_qldate(QlDate qdate)
71+
cdef QlDate _qldate_from_pydate(object date)

quantlib/time/date.pyx

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,16 @@ from . cimport frequency
1212

1313
from ._date cimport (
1414
Date as QlDate, todaysDate, nextWeekday, endOfMonth, isEndOfMonth,
15-
minDate, maxDate, Year, Day, Month as QlMonth, Hour, Minute, Second, Millisecond,
15+
minDate, maxDate, Year, Day, Hour, Minute, Second, Millisecond,
1616
Microsecond, isLeap, Size, nthWeekday, serial_type, Integer
1717
)
1818
from ._period cimport Period as QlPeriod, parse, unary_minus
1919
from enum import IntEnum
20-
20+
globals().update(getattr(Weekday, "__members__"))
21+
globals().update(getattr(Month, "__members__"))
2122
# Python imports
2223
import_datetime()
2324

24-
cpdef enum Month:
25-
January = _date.January
26-
February = _date.February
27-
March = _date.March
28-
April = _date.April
29-
May = _date.May
30-
June = _date.June
31-
July = _date.July
32-
August = _date.August
33-
September = _date.September
34-
October = _date.October
35-
November = _date.November
36-
December = _date.December
37-
Jan = _date.Jan
38-
Feb = _date.Feb
39-
Mar = _date.Mar
40-
Apr = _date.Apr
41-
Jun = _date.Jun
42-
Jul = _date.Jul
43-
Aug = _date.Aug
44-
Sep = _date.Sep
45-
Oct = _date.Oct
46-
Nov = _date.Nov
47-
Dec = _date.Dec
48-
49-
cpdef enum Weekday:
50-
Sunday = _date.Sunday
51-
Monday = _date.Monday
52-
Tuesday = _date.Tuesday
53-
Wednesday = _date.Wednesday
54-
Thursday = _date.Thursday
55-
Friday = _date.Friday
56-
Saturday = _date.Saturday
57-
Sun = _date.Sun
58-
Mon = _date.Mon
59-
Tue = _date.Tue
60-
Wed = _date.Wed
61-
Thu = _date.Thu
62-
Fri = _date.Fri
63-
Sat = _date.Sat
64-
65-
6625
class TimeUnit(IntEnum):
6726
Days = _period.Days #: Days = 0
6827
Weeks = _period.Weeks #: Weeks = 1
@@ -269,9 +228,9 @@ cdef class Date:
269228
if day is None and month is None and year is None:
270229
self._thisptr = QlDate()
271230
elif day is not None and month is not None and year is not None:
272-
self._thisptr = QlDate(<Day>day, <QlMonth>month, <Year>year)
231+
self._thisptr = QlDate(<Day>day, <Month>month, <Year>year)
273232
elif hours is not None and minutes is not None and seconds is not None:
274-
self._thisptr = QlDate(<Day>day, <QlMonth>month, <Year>year, <Hour>hours, <Minute>minutes, <Second>seconds, millisec, microsec)
233+
self._thisptr = QlDate(<Day>day, <Month>month, <Year>year, <Hour>hours, <Minute>minutes, <Second>seconds, millisec, microsec)
275234
else:
276235
raise ValueError("Invalid constructor")
277236

0 commit comments

Comments
 (0)