Skip to content

Commit a81b402

Browse files
committed
implement (slow) np.divmod for numpy < 1.13.0
1 parent 0416b06 commit a81b402

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pandas/_libs/tslibs/timestamps.pyx

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ class RoundTo(enum.Enum):
6767
NEAREST_HALF_MINUS_INFTY = 4
6868

6969

70+
cdef inline _npdivmod(x1, x2):
71+
"""implement divmod for numpy < 1.13"""
72+
return np.floor_divide(x1, x2), np.remainder(x1, x2)
73+
74+
75+
try:
76+
from numpy import divmod as npdivmod
77+
except ImportError:
78+
npdivmod = _npdivmod
79+
80+
7081
cdef inline _floor_int64(v, u):
7182
return v - np.remainder(v, u)
7283

@@ -112,7 +123,7 @@ def round_nsint64(values, mode: RoundTo, freq):
112123
# for odd unit there is no need of a tie break
113124
if unit % 2:
114125
return _rounddown_int64(values, unit)
115-
d, r = np.divmod(values, unit)
126+
d, r = npdivmod(values, unit)
116127
mask = np.logical_or(
117128
r > (unit // 2),
118129
np.logical_and(r == (unit // 2), d % 2)

0 commit comments

Comments
 (0)