Skip to content

Commit 83dea23

Browse files
ArmavicaricardoV94
authored andcommitted
Remove npy<2 compatibility for OverflowError
1 parent 80a5c15 commit 83dea23

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

pytensor/npy_2_compat.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
ndarray_c_version = np.core._multiarray_umath._get_ndarray_c_version() # type: ignore[attr-defined]
3636

3737

38-
# used in tests: the type of error thrown if a value is too large for the specified
39-
# numpy data type is different in numpy 2.x
40-
UintOverflowError = OverflowError if using_numpy_2 else TypeError
41-
42-
4338
# to patch up some of the C code, we need to use these special values...
4439
if using_numpy_2:
4540
numpy_axis_is_none_flag = np.iinfo(np.int32).min # the value of "NPY_RAVEL_AXIS"

tests/compile/function/test_function.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pytensor.compile.function import function, function_dump
1111
from pytensor.compile.io import In
1212
from pytensor.configdefaults import config
13-
from pytensor.npy_2_compat import UintOverflowError
1413
from pytensor.tensor.type import (
1514
bscalar,
1615
bvector,
@@ -176,11 +175,11 @@ def test_in_allow_downcast_int(self):
176175
assert np.array_equal(f([2**20], np.ones(1, dtype="int8"), 1), [2])
177176

178177
# Value too big for b, raises OverflowError (in numpy >= 2.0... TypeError in numpy < 2.0)
179-
with pytest.raises(UintOverflowError):
178+
with pytest.raises(OverflowError):
180179
f([3], [312], 1)
181180

182181
# Value too big for c, raises OverflowError
183-
with pytest.raises(UintOverflowError):
182+
with pytest.raises(OverflowError):
184183
f([3], [6], 806)
185184

186185
def test_in_allow_downcast_floatX(self):

tests/compile/function/test_pfunc.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pytensor.compile.sharedvalue import shared
1010
from pytensor.configdefaults import config
1111
from pytensor.graph.utils import MissingInputError
12-
from pytensor.npy_2_compat import UintOverflowError
1312
from pytensor.tensor.math import sum as pt_sum
1413
from pytensor.tensor.type import (
1514
bscalar,
@@ -239,11 +238,11 @@ def test_param_allow_downcast_int(self):
239238
assert np.all(f([2**20], np.ones(1, dtype="int8"), 1) == 2)
240239

241240
# Value too big for b, raises OverflowError in numpy >= 2.0, TypeError in numpy <2.0
242-
with pytest.raises(UintOverflowError):
241+
with pytest.raises(OverflowError):
243242
f([3], [312], 1)
244243

245244
# Value too big for c, raises OverflowError in numpy >= 2.0, TypeError in numpy <2.0
246-
with pytest.raises(UintOverflowError):
245+
with pytest.raises(OverflowError):
247246
f([3], [6], 806)
248247

249248
def test_param_allow_downcast_floatX(self):
@@ -329,7 +328,7 @@ def test_allow_input_downcast_int(self):
329328
g([3], np.array([6], dtype="int16"), 0)
330329

331330
# Value too big for b, raises OverflowError in numpy >= 2.0, TypeError in numpy <2.0
332-
with pytest.raises(UintOverflowError):
331+
with pytest.raises(OverflowError):
333332
g([3], [312], 0)
334333

335334
h = pfunc([a, b, c], (a + b + c)) # Default: allow_input_downcast=None
@@ -340,7 +339,7 @@ def test_allow_input_downcast_int(self):
340339
h([3], np.array([6], dtype="int16"), 0)
341340

342341
# Value too big for b, raises OverflowError in numpy >= 2.0, TypeError in numpy <2.0
343-
with pytest.raises(UintOverflowError):
342+
with pytest.raises(OverflowError):
344343
h([3], [312], 0)
345344

346345
def test_allow_downcast_floatX(self):

0 commit comments

Comments
 (0)