-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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 | ||
|
||
|
@@ -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): | ||
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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) | ||
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.