Skip to content

remove enum import for PY2 compat, xref #22802 #24170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import enum
import warnings

from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
Expand Down Expand Up @@ -71,8 +70,7 @@ cdef inline object create_timestamp_from_ts(int64_t value,
return ts_base


@enum.unique
class RoundTo(enum.Enum):
class RoundTo(object):
"""
enumeration defining the available rounding modes

Expand Down Expand Up @@ -105,11 +103,25 @@ class RoundTo(enum.Enum):
.. [6] "Round half to even"
https://en.wikipedia.org/wiki/Rounding#Round_half_to_even
"""
MINUS_INFTY = 0
PLUS_INFTY = 1
NEAREST_HALF_EVEN = 2
NEAREST_HALF_PLUS_INFTY = 3
NEAREST_HALF_MINUS_INFTY = 4
@property
def MINUS_INFTY(self):
return 0

@property
def PLUS_INFTY(self):
return 1

@property
def NEAREST_HALF_EVEN(self):
return 2

@property
def NEAREST_HALF_PLUS_INFTY(self):
return 3

@property
def NEAREST_HALF_MINUS_INFTY(self):
return 4


cdef inline _npdivmod(x1, x2):
Expand Down Expand Up @@ -152,20 +164,17 @@ def round_nsint64(values, mode, freq):
:obj:`ndarray`
"""

if not isinstance(mode, RoundTo):
raise ValueError('mode should be a RoundTo member')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it matters (probably doesn't) but it seems like bad modes will now raise an AssertionError instead of a ValueError.


unit = to_offset(freq).nanos

if mode is RoundTo.MINUS_INFTY:
if mode == RoundTo.MINUS_INFTY:
return _floor_int64(values, unit)
elif mode is RoundTo.PLUS_INFTY:
elif mode == RoundTo.PLUS_INFTY:
return _ceil_int64(values, unit)
elif mode is RoundTo.NEAREST_HALF_MINUS_INFTY:
elif mode == RoundTo.NEAREST_HALF_MINUS_INFTY:
return _rounddown_int64(values, unit)
elif mode is RoundTo.NEAREST_HALF_PLUS_INFTY:
elif mode == RoundTo.NEAREST_HALF_PLUS_INFTY:
return _roundup_int64(values, unit)
elif mode is RoundTo.NEAREST_HALF_EVEN:
elif mode == RoundTo.NEAREST_HALF_EVEN:
# for odd unit there is no need of a tie break
if unit % 2:
return _rounddown_int64(values, unit)
Expand All @@ -179,8 +188,8 @@ def round_nsint64(values, mode, freq):

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


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