1diff --git a/pyquaternion/test/test_quaternion.py b/pyquaternion/test/test_quaternion.py
2index f56afff..7178b52 100644
3--- a/pyquaternion/test/test_quaternion.py
4+++ b/pyquaternion/test/test_quaternion.py
5@@ -50,6 +50,16 @@ ALMOST_EQUAL_TOLERANCE = 13
6 def randomElements():
7 return tuple(np.random.uniform(-1, 1, 4))
8
9+# In numpy 2, repr(np.float64(0.123)) becomes "np.float64(0.123)"
10+# which means it's not directly a parseable float. In numpy 1 that
11+# used to be the case. This hack papers over that
12+def repr_np(x):
13+ has_item = hasattr(x, 'item')
14+ if isinstance(x, np.generic) and has_item:
15+ return repr(x.item())
16+ else:
17+ return repr(x)
18+
19 class TestQuaternionInitialisation(unittest.TestCase):
20
21 def test_init_default(self):
22@@ -77,7 +87,7 @@ class TestQuaternionInitialisation(unittest.TestCase):
23 def test_init_from_scalar(self):
24 s = random()
25 q1 = Quaternion(s)
26- q2 = Quaternion(repr(s))
27+ q2 = Quaternion(repr_np(s))
28 self.assertIsInstance(q1, Quaternion)
29 self.assertIsInstance(q2, Quaternion)
30 self.assertEqual(q1, Quaternion(s, 0.0, 0.0, 0.0))
31@@ -90,8 +100,8 @@ class TestQuaternionInitialisation(unittest.TestCase):
32 def test_init_from_elements(self):
33 a, b, c, d = randomElements()
34 q1 = Quaternion(a, b, c, d)
35- q2 = Quaternion(repr(a), repr(b), repr(c), repr(d))
36- q3 = Quaternion(a, repr(b), c, d)
37+ q2 = Quaternion(repr_np(a), repr_np(b), repr_np(c), repr_np(d))
38+ q3 = Quaternion(a, repr_np(b), c, d)
39 self.assertIsInstance(q1, Quaternion)
40 self.assertIsInstance(q2, Quaternion)
41 self.assertIsInstance(q3, Quaternion)
42@@ -154,7 +164,7 @@ class TestQuaternionInitialisation(unittest.TestCase):
43 def test_init_from_explicit_elements(self):
44 e1, e2, e3, e4 = randomElements()
45 q1 = Quaternion(w=e1, x=e2, y=e3, z=e4)
46- q2 = Quaternion(a=e1, b=repr(e2), c=e3, d=e4)
47+ q2 = Quaternion(a=e1, b=repr_np(e2), c=e3, d=e4)
48 q3 = Quaternion(a=e1, i=e2, j=e3, k=e4)
49 q4 = Quaternion(a=e1)
50 self.assertIsInstance(q1, Quaternion)
51@@ -525,7 +535,7 @@ class TestQuaternionArithmetic(unittest.TestCase):
52 q3 = q1
53 self.assertEqual(q1 * s, q2) # post-multiply by scalar
54 self.assertEqual(s * q1, q2) # pre-multiply by scalar
55- q3 *= repr(s)
56+ q3 *= repr_np(s)
57 self.assertEqual(q3, q2)
58
59 def test_multiply_incorrect_type(self):
60@@ -595,7 +605,7 @@ class TestQuaternionArithmetic(unittest.TestCase):
61 with self.assertRaises(ZeroDivisionError):
62 s / q1
63
64- q3 /= repr(s)
65+ q3 /= repr_np(s)
66 self.assertEqual(q3, q2)
67
68 with self.assertRaises(ZeroDivisionError):