|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| -import enum |
3 | 2 | import warnings
|
4 | 3 |
|
5 | 4 | from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
|
@@ -71,8 +70,7 @@ cdef inline object create_timestamp_from_ts(int64_t value,
|
71 | 70 | return ts_base
|
72 | 71 |
|
73 | 72 |
|
74 |
| -@enum.unique |
75 |
| -class RoundTo(enum.Enum): |
| 73 | +class RoundTo: |
76 | 74 | """
|
77 | 75 | enumeration defining the available rounding modes
|
78 | 76 |
|
@@ -105,11 +103,25 @@ class RoundTo(enum.Enum):
|
105 | 103 | .. [6] "Round half to even"
|
106 | 104 | https://en.wikipedia.org/wiki/Rounding#Round_half_to_even
|
107 | 105 | """
|
108 |
| - MINUS_INFTY = 0 |
109 |
| - PLUS_INFTY = 1 |
110 |
| - NEAREST_HALF_EVEN = 2 |
111 |
| - NEAREST_HALF_PLUS_INFTY = 3 |
112 |
| - NEAREST_HALF_MINUS_INFTY = 4 |
| 106 | + @property |
| 107 | + def MINUS_INFTY(self): |
| 108 | + return 0 |
| 109 | + |
| 110 | + @property |
| 111 | + def PLUS_INFTY(self): |
| 112 | + return 1 |
| 113 | + |
| 114 | + @property |
| 115 | + def NEAREST_HALF_EVEN(self): |
| 116 | + return 2 |
| 117 | + |
| 118 | + @property |
| 119 | + def NEAREST_HALF_PLUS_INFTY(self): |
| 120 | + return 3 |
| 121 | + |
| 122 | + @property |
| 123 | + def NEAREST_HALF_MINUS_INFTY(self): |
| 124 | + return 4 |
113 | 125 |
|
114 | 126 |
|
115 | 127 | cdef inline _npdivmod(x1, x2):
|
@@ -152,20 +164,17 @@ def round_nsint64(values, mode, freq):
|
152 | 164 | :obj:`ndarray`
|
153 | 165 | """
|
154 | 166 |
|
155 |
| - if not isinstance(mode, RoundTo): |
156 |
| - raise ValueError('mode should be a RoundTo member') |
157 |
| - |
158 | 167 | unit = to_offset(freq).nanos
|
159 | 168 |
|
160 |
| - if mode is RoundTo.MINUS_INFTY: |
| 169 | + if mode == RoundTo.MINUS_INFTY: |
161 | 170 | return _floor_int64(values, unit)
|
162 |
| - elif mode is RoundTo.PLUS_INFTY: |
| 171 | + elif mode == RoundTo.PLUS_INFTY: |
163 | 172 | return _ceil_int64(values, unit)
|
164 |
| - elif mode is RoundTo.NEAREST_HALF_MINUS_INFTY: |
| 173 | + elif mode == RoundTo.NEAREST_HALF_MINUS_INFTY: |
165 | 174 | return _rounddown_int64(values, unit)
|
166 |
| - elif mode is RoundTo.NEAREST_HALF_PLUS_INFTY: |
| 175 | + elif mode == RoundTo.NEAREST_HALF_PLUS_INFTY: |
167 | 176 | return _roundup_int64(values, unit)
|
168 |
| - elif mode is RoundTo.NEAREST_HALF_EVEN: |
| 177 | + elif mode == RoundTo.NEAREST_HALF_EVEN: |
169 | 178 | # for odd unit there is no need of a tie break
|
170 | 179 | if unit % 2:
|
171 | 180 | return _rounddown_int64(values, unit)
|
|
0 commit comments