Skip to content

Commit ec4a12e

Browse files
jrebackPingviinituutti
authored andcommitted
remove enum import for PY2 compat, xref pandas-dev#22802 (pandas-dev#24170)
1 parent 4b7dc81 commit ec4a12e

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

pandas/_libs/tslibs/timestamps.pyx

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import enum
32
import warnings
43

54
from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
@@ -71,8 +70,7 @@ cdef inline object create_timestamp_from_ts(int64_t value,
7170
return ts_base
7271

7372

74-
@enum.unique
75-
class RoundTo(enum.Enum):
73+
class RoundTo(object):
7674
"""
7775
enumeration defining the available rounding modes
7876
@@ -105,11 +103,25 @@ class RoundTo(enum.Enum):
105103
.. [6] "Round half to even"
106104
https://en.wikipedia.org/wiki/Rounding#Round_half_to_even
107105
"""
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
113125

114126

115127
cdef inline _npdivmod(x1, x2):
@@ -152,20 +164,17 @@ def round_nsint64(values, mode, freq):
152164
:obj:`ndarray`
153165
"""
154166

155-
if not isinstance(mode, RoundTo):
156-
raise ValueError('mode should be a RoundTo member')
157-
158167
unit = to_offset(freq).nanos
159168

160-
if mode is RoundTo.MINUS_INFTY:
169+
if mode == RoundTo.MINUS_INFTY:
161170
return _floor_int64(values, unit)
162-
elif mode is RoundTo.PLUS_INFTY:
171+
elif mode == RoundTo.PLUS_INFTY:
163172
return _ceil_int64(values, unit)
164-
elif mode is RoundTo.NEAREST_HALF_MINUS_INFTY:
173+
elif mode == RoundTo.NEAREST_HALF_MINUS_INFTY:
165174
return _rounddown_int64(values, unit)
166-
elif mode is RoundTo.NEAREST_HALF_PLUS_INFTY:
175+
elif mode == RoundTo.NEAREST_HALF_PLUS_INFTY:
167176
return _roundup_int64(values, unit)
168-
elif mode is RoundTo.NEAREST_HALF_EVEN:
177+
elif mode == RoundTo.NEAREST_HALF_EVEN:
169178
# for odd unit there is no need of a tie break
170179
if unit % 2:
171180
return _rounddown_int64(values, unit)
@@ -179,8 +188,8 @@ def round_nsint64(values, mode, freq):
179188

180189
# if/elif above should catch all rounding modes defined in enum 'RoundTo':
181190
# if flow of control arrives here, it is a bug
182-
raise AssertionError("round_nsint64 called with an unrecognized "
183-
"rounding mode")
191+
raise ValueError("round_nsint64 called with an unrecognized "
192+
"rounding mode")
184193

185194

186195
# This is PITA. Because we inherit from datetime, which has very specific

0 commit comments

Comments
 (0)