summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-04-07 13:03:04 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-02 19:12:17 +0200
commit48020e87513c8632655dc0939cae802aab07616e (patch)
treed285d390a9edc474118bffde40d5997b17f8b2f7
parentb84a53df9346a73fe8f6df0aaad8727f9bf56076 (diff)
downloadnumpy-48020e87513c8632655dc0939cae802aab07616e.tar.gz
BUG: Fix TestConversion.test_to_int_scalar() on Python.
The delegation of int() to __trunc__ was deprecated in Python 3.11, see https://github.com/python/cpython/commit/b4bd1e1422997de61faf506b4916e83013bc7d21
-rw-r--r--numpy/core/tests/test_multiarray.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 1b29c1f8b..f4454130d 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -8583,11 +8583,16 @@ class TestConversion:
assert_equal(5, int_func(np.bytes_(b'5')))
assert_equal(6, int_func(np.unicode_(u'6')))
- class HasTrunc:
- def __trunc__(self):
- return 3
- assert_equal(3, int_func(np.array(HasTrunc())))
- assert_equal(3, int_func(np.array([HasTrunc()])))
+ # The delegation of int() to __trunc__ was deprecated in
+ # Python 3.11.
+ if sys.version_info < (3, 11):
+ class HasTrunc:
+ def __trunc__(self):
+ return 3
+ assert_equal(3, int_func(np.array(HasTrunc())))
+ assert_equal(3, int_func(np.array([HasTrunc()])))
+ else:
+ pass
class NotConvertible:
def __int__(self):