Repository: sympy/sympy (Python)

Issue:
incompatibility with latest version of numpy
Dear developers,

I am using the latest numpy version (2.1.0) in combination with the latest version of sympy (1.13.2). When I run this short code snippet, an error is returned:

```
from sympy.physics.wigner import clebsch_gordan
import numpy as np
x = np.zeros(6).astype(np.int64)
clebsch_gordan(*x)
```

```
Traceback (most recent call last):
  File "/home/jonas/anaconda3/envs/schnetpack/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-599650c24b27>", line 4, in <module>
    clebsch_gordan(*x)
  File "/home/jonas/anaconda3/envs/schnetpack/lib/python3.10/site-packages/sympy/physics/wigner.py", line 327, in clebsch_gordan
    wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3)
  File "/home/jonas/anaconda3/envs/schnetpack/lib/python3.10/site-packages/sympy/physics/wigner.py", line 219, in wigner_3j
    j_1, j_2, j_3, m_1, m_2, m_3 = map(_int_or_halfint,
  File "/home/jonas/anaconda3/envs/schnetpack/lib/python3.10/site-packages/sympy/physics/wigner.py", line 127, in _int_or_halfint
    raise ValueError("expecting integer or half-integer, got %s" % value)
ValueError: expecting integer or half-integer, got 0
```

When I downgrade to sympy 1.12 the code works fine. Are you aware of this and is a fix planned in the near future?

Thank you very much for providing this nice package and looking forward to hearing from you.
Best regards, 
Jonas


Discussion:
It seems that this code does not expect a numpy float:
https://github.com/sympy/sympy/blob/01a25577c8acda8f50a7d35eb0971fc0a1e17344/sympy/physics/wigner.py#L111-L127
It works if using integers:
```python
In [4]: from sympy.physics.wigner import clebsch_gordan
   ...: import numpy as np
   ...: clebsch_gordan(*[0]*6)
Out[4]: 1
```
I assume that is the correct answer.

Probably `sympify` should be used somewhere to fix this rather than checking for exact types in the way that it does since `sympify` already handles numpy types:
```python
In [7]: sympify(np.float64(0.5))
Out[7]: 0.500000000000000

In [8]: type(sympify(np.float64(0.5)))
Out[8]: sympy.core.numbers.Float
```
I have bisected the bug to a38e3e701dadc1a97ffc232bf5d110ce1f4f175b from gh-26232.
A workaround for this is just to cal `sympify`:
```python
In [6]: from sympy.physics.wigner import clebsch_gordan
   ...: import numpy as np
   ...: x = np.zeros(6).astype(np.int64)
   ...: clebsch_gordan(*sympify(x))
Out[6]: 1
```
It would also not be hard to fix in SymPy as well: just add a call to `sympify` somewhere.
Thank you very much for the work around! :)
Fix is in gh-27066



Patch:
diff --git a/sympy/physics/wigner.py b/sympy/physics/wigner.py
index 75e4b52aea4a..f55cd3abb83b 100644
--- a/sympy/physics/wigner.py
+++ b/sympy/physics/wigner.py
@@ -323,9 +323,16 @@ def clebsch_gordan(j_1, j_2, j_3, m_1, m_2, m_3):
 
     - Jens Rasch (2009-03-24): initial version
     """
-    res = (-1) ** sympify(j_1 - j_2 + m_3) * sqrt(2 * j_3 + 1) * \
-        wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3)
-    return res
+    j_1 = sympify(j_1)
+    j_2 = sympify(j_2)
+    j_3 = sympify(j_3)
+    m_1 = sympify(m_1)
+    m_2 = sympify(m_2)
+    m_3 = sympify(m_3)
+
+    w = wigner_3j(j_1, j_2, j_3, m_1, m_2, -m_3)
+
+    return (-1) ** (j_1 - j_2 + m_3) * sqrt(2 * j_3 + 1) * w
 
 
 def _big_delta_coeff(aa, bb, cc, prec=None):


Test patch:
diff --git a/sympy/physics/tests/test_clebsch_gordan.py b/sympy/physics/tests/test_clebsch_gordan.py
index 68bfa0ac94df..906e62bb3903 100644
--- a/sympy/physics/tests/test_clebsch_gordan.py
+++ b/sympy/physics/tests/test_clebsch_gordan.py
@@ -8,7 +8,7 @@
 from sympy.matrices.dense import Matrix
 from sympy.physics.wigner import (clebsch_gordan, wigner_9j, wigner_6j, gaunt,
         real_gaunt, racah, dot_rot_grad_Ynm, wigner_3j, wigner_d_small, wigner_d)
-from sympy.testing.pytest import raises
+from sympy.testing.pytest import raises, skip
 
 # for test cases, refer : https://en.wikipedia.org/wiki/Table_of_Clebsch%E2%80%93Gordan_coefficients
 
@@ -55,6 +55,14 @@ def test_clebsch_gordan():
     assert clebsch_gordan(p, h, l, k, 1, l) == 1/sqrt(15)
 
 
+def test_clebsch_gordan_numpy():
+    try:
+        import numpy as np
+    except ImportError:
+        skip("numpy not installed")
+    assert clebsch_gordan(*np.zeros(6).astype(np.int64)) == 1
+
+
 def test_wigner():
     def tn(a, b):
         return (a - b).n(64) < S('1e-64')