Skip to content

Commit 1b07fde

Browse files
Backport PR #41990: CI: troubleshoot py310 build (#42019)
Co-authored-by: jbrockmendel <[email protected]>
1 parent dbaec43 commit 1b07fde

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1030,9 +1030,9 @@ def rank_1d(
10301030
if rank_t is object:
10311031
nan_fill_val = Infinity()
10321032
elif rank_t is int64_t:
1033-
nan_fill_val = np.iinfo(np.int64).max
1033+
nan_fill_val = util.INT64_MAX
10341034
elif rank_t is uint64_t:
1035-
nan_fill_val = np.iinfo(np.uint64).max
1035+
nan_fill_val = util.UINT64_MAX
10361036
else:
10371037
nan_fill_val = np.inf
10381038
order = (masked_vals, mask, labels)
@@ -1393,7 +1393,7 @@ def rank_2d(
13931393

13941394
# int64 and datetimelike
13951395
else:
1396-
nan_value = np.iinfo(np.int64).max
1396+
nan_value = util.INT64_MAX
13971397

13981398
else:
13991399
if rank_t is object:

pandas/_libs/lib.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class NoDefault(Enum): ...
2525

2626
no_default: NoDefault
2727

28+
i8max: int
29+
u8max: int
30+
2831
def item_from_zerodim(val: object) -> object: ...
2932
def infer_dtype(value: object, skipna: bool = True) -> str: ...
3033
def is_iterator(obj: object) -> bool: ...

pandas/_libs/lib.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ cdef:
118118

119119
float64_t NaN = <float64_t>np.NaN
120120

121+
# python-visible
122+
i8max = <int64_t>INT64_MAX
123+
u8max = <uint64_t>UINT64_MAX
124+
121125

122126
@cython.wraparound(False)
123127
@cython.boundscheck(False)

pandas/core/algorithms.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1092,18 +1092,19 @@ def checked_add_with_arr(
10921092
# it is negative, we then check whether its sum with the element in
10931093
# 'arr' exceeds np.iinfo(np.int64).min. If so, we have an overflow
10941094
# error as well.
1095+
i8max = lib.i8max
1096+
i8min = iNaT
1097+
10951098
mask1 = b2 > 0
10961099
mask2 = b2 < 0
10971100

10981101
if not mask1.any():
1099-
to_raise = ((np.iinfo(np.int64).min - b2 > arr) & not_nan).any()
1102+
to_raise = ((i8min - b2 > arr) & not_nan).any()
11001103
elif not mask2.any():
1101-
to_raise = ((np.iinfo(np.int64).max - b2 < arr) & not_nan).any()
1104+
to_raise = ((i8max - b2 < arr) & not_nan).any()
11021105
else:
1103-
to_raise = (
1104-
(np.iinfo(np.int64).max - b2[mask1] < arr[mask1]) & not_nan[mask1]
1105-
).any() or (
1106-
(np.iinfo(np.int64).min - b2[mask2] > arr[mask2]) & not_nan[mask2]
1106+
to_raise = ((i8max - b2[mask1] < arr[mask1]) & not_nan[mask1]).any() or (
1107+
(i8min - b2[mask2] > arr[mask2]) & not_nan[mask2]
11071108
).any()
11081109

11091110
if to_raise:

pandas/core/arrays/_ranges.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88

9+
from pandas._libs.lib import i8max
910
from pandas._libs.tslibs import (
1011
BaseOffset,
1112
OutOfBoundsDatetime,
@@ -103,7 +104,7 @@ def _generate_range_overflow_safe(
103104
# GH#14187 raise instead of incorrectly wrapping around
104105
assert side in ["start", "end"]
105106

106-
i64max = np.uint64(np.iinfo(np.int64).max)
107+
i64max = np.uint64(i8max)
107108
msg = f"Cannot generate range with {side}={endpoint} and periods={periods}"
108109

109110
with np.errstate(over="raise"):
@@ -180,7 +181,7 @@ def _generate_range_overflow_safe_signed(
180181
# error: Incompatible types in assignment (expression has type
181182
# "unsignedinteger[_64Bit]", variable has type "signedinteger[_64Bit]")
182183
result = np.uint64(endpoint) + np.uint64(addend) # type: ignore[assignment]
183-
i64max = np.uint64(np.iinfo(np.int64).max)
184+
i64max = np.uint64(i8max)
184185
assert result > i64max
185186
if result <= i64max + np.uint64(stride):
186187
# error: Incompatible return value type (got "unsignedinteger", expected

pandas/core/nanops.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _get_fill_value(
205205
else:
206206
if fill_value_typ == "+inf":
207207
# need the max int here
208-
return np.iinfo(np.int64).max
208+
return lib.i8max
209209
else:
210210
return iNaT
211211

@@ -376,7 +376,7 @@ def _wrap_results(result, dtype: np.dtype, fill_value=None):
376376
result = np.nan
377377

378378
# raise if we have a timedelta64[ns] which is too large
379-
if np.fabs(result) > np.iinfo(np.int64).max:
379+
if np.fabs(result) > lib.i8max:
380380
raise ValueError("overflow in timedelta operation")
381381

382382
result = Timedelta(result, unit="ns")
@@ -1758,7 +1758,7 @@ def na_accum_func(values: ArrayLike, accum_func, *, skipna: bool) -> ArrayLike:
17581758
if accum_func == np.minimum.accumulate:
17591759
# Note: the accum_func comparison fails as an "is" comparison
17601760
y = values.view("i8")
1761-
y[mask] = np.iinfo(np.int64).max
1761+
y[mask] = lib.i8max
17621762
changed = True
17631763
else:
17641764
y = values

pandas/core/sorting.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
from pandas import MultiIndex
4141
from pandas.core.indexes.base import Index
4242

43-
_INT64_MAX = np.iinfo(np.int64).max
44-
4543

4644
def get_indexer_indexer(
4745
target: Index,
@@ -133,7 +131,7 @@ def _int64_cut_off(shape) -> int:
133131
acc = 1
134132
for i, mul in enumerate(shape):
135133
acc *= int(mul)
136-
if not acc < _INT64_MAX:
134+
if not acc < lib.i8max:
137135
return i
138136
return len(shape)
139137

@@ -153,7 +151,7 @@ def maybe_lift(lab, size) -> tuple[np.ndarray, int]:
153151
labels = list(labels)
154152

155153
# Iteratively process all the labels in chunks sized so less
156-
# than _INT64_MAX unique int ids will be required for each chunk
154+
# than lib.i8max unique int ids will be required for each chunk
157155
while True:
158156
# how many levels can be done without overflow:
159157
nlev = _int64_cut_off(lshape)
@@ -215,7 +213,7 @@ def is_int64_overflow_possible(shape) -> bool:
215213
for x in shape:
216214
the_prod *= int(x)
217215

218-
return the_prod >= _INT64_MAX
216+
return the_prod >= lib.i8max
219217

220218

221219
def decons_group_index(comp_labels, shape):

pandas/core/util/hashing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import numpy as np
1616

17+
from pandas._libs import lib
1718
from pandas._libs.hashing import hash_object_array
1819
from pandas._typing import (
1920
ArrayLike,
@@ -244,7 +245,7 @@ def _hash_categorical(cat: Categorical, encoding: str, hash_key: str) -> np.ndar
244245
result = np.zeros(len(mask), dtype="uint64")
245246

246247
if mask.any():
247-
result[mask] = np.iinfo(np.uint64).max
248+
result[mask] = lib.u8max
248249

249250
return result
250251

pandas/tests/scalar/timedelta/test_timedelta.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import pytest
66

7+
from pandas._libs import lib
78
from pandas._libs.tslibs import (
89
NaT,
910
iNaT,
@@ -391,8 +392,7 @@ def test_round_implementation_bounds(self):
391392
"method", [Timedelta.round, Timedelta.floor, Timedelta.ceil]
392393
)
393394
def test_round_sanity(self, method, n, request):
394-
iinfo = np.iinfo(np.int64)
395-
val = np.random.randint(iinfo.min + 1, iinfo.max, dtype=np.int64)
395+
val = np.random.randint(iNaT + 1, lib.i8max, dtype=np.int64)
396396
td = Timedelta(val)
397397

398398
assert method(td, "ns") == td
@@ -552,8 +552,8 @@ def test_implementation_limits(self):
552552

553553
# GH 12727
554554
# timedelta limits correspond to int64 boundaries
555-
assert min_td.value == np.iinfo(np.int64).min + 1
556-
assert max_td.value == np.iinfo(np.int64).max
555+
assert min_td.value == iNaT + 1
556+
assert max_td.value == lib.i8max
557557

558558
# Beyond lower limit, a NAT before the Overflow
559559
assert (min_td - Timedelta(1, "ns")) is NaT

pandas/tests/scalar/timestamp/test_unary_ops.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import pytz
77
from pytz import utc
88

9+
from pandas._libs import lib
910
from pandas._libs.tslibs import (
1011
NaT,
1112
Timedelta,
1213
Timestamp,
1314
conversion,
15+
iNaT,
1416
to_offset,
1517
)
1618
from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG
@@ -279,8 +281,7 @@ def test_round_implementation_bounds(self):
279281
"method", [Timestamp.round, Timestamp.floor, Timestamp.ceil]
280282
)
281283
def test_round_sanity(self, method, n):
282-
iinfo = np.iinfo(np.int64)
283-
val = np.random.randint(iinfo.min + 1, iinfo.max, dtype=np.int64)
284+
val = np.random.randint(iNaT + 1, lib.i8max, dtype=np.int64)
284285
ts = Timestamp(val)
285286

286287
def checker(res, ts, nanos):

0 commit comments

Comments
 (0)