Repository: sympy/sympy

Issue:
wigner_3j Violating numpy behavioral subtyping
Dear Developers,

I am currently using the most up to date versions of numpy (2.1.3) and sympy (1.13.3). I get an error when I run the following code snippet.

```
import numpy as np
from sympy.physics.wigner import wigner_3j

y = np.float64(6.0)
x = wigner_3j(2, y, 4.0, 0, 0, 0)
```

Error:

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[5], line 5
      2 from sympy.physics.wigner import wigner_3j
      4 y = np.float64(6.0)
----> 5 x = wigner_3j(2, y, 4.0, 0, 0, 0)

File ~\code\.venv\jlab\lib\site-packages\sympy\physics\wigner.py:219, in wigner_3j(j_1, j_2, j_3, m_1, m_2, m_3)
    130 def wigner_3j(j_1, j_2, j_3, m_1, m_2, m_3):
    131     r"""
    132     Calculate the Wigner 3j symbol `\operatorname{Wigner3j}(j_1,j_2,j_3,m_1,m_2,m_3)`.
    133 
   (...)
    216     - Jens Rasch (2009-03-24): initial version
    217     """
--> 219     j_1, j_2, j_3, m_1, m_2, m_3 = map(_int_or_halfint,
    220                                        [j_1, j_2, j_3, m_1, m_2, m_3])
    222     if m_1 + m_2 + m_3 != 0:
    223         return S.Zero

File ~\code\.venv\jlab\lib\site-packages\sympy\physics\wigner.py:127, in _int_or_halfint(value)
    125 elif isinstance(value, Float):
    126     return _int_or_halfint(float(value))
--> 127 raise ValueError("expecting integer or half-integer, got %s" % value)

ValueError: expecting integer or half-integer, got 6.0
```

It appears that wigner_3j violates behavioral subtyping/no longer accepts numpy floats or ints. This issue appears to be similar to issue #27012, and was fixed in pr #27066. Can this also be fixed for the wigner_3j function too?

Thanks,
Simon

Discussion:

Patch:
diff --git a/.mailmap b/.mailmap
index a9c12f5555..b3df504d8a 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1272,6 +1272,7 @@ Roman Inflianskas <infroma@gmail.com>
 Ronan Lamy <ronan.lamy@gmail.com> <Ronan.Lamy@normalesup.org>
 Rudr Tiwari <rudrtiwari@gmail.com>
 Rupesh Harode <rupeshharode@gmail.com>
+Rushabh Mehta <mehtarushabh2005@gmail.com> RushabhMehta2005 <139112780+RushabhMehta2005@users.noreply.github.com>
 Ruslan Pisarev <rpisarev@cloudlinux.com> <ruslan@rpisarev.org.ua>
 Ryan Krauss <ryanlists@gmail.com>
 Rémy Léone <rleone@online.net>
diff --git a/sympy/physics/wigner.py b/sympy/physics/wigner.py
index e04e9c6f69..3dcd2f8f46 100644
--- a/sympy/physics/wigner.py
+++ b/sympy/physics/wigner.py
@@ -216,8 +216,9 @@ def wigner_3j(j_1, j_2, j_3, m_1, m_2, m_3):
     - Jens Rasch (2009-03-24): initial version
     """
 
-    j_1, j_2, j_3, m_1, m_2, m_3 = map(_int_or_halfint,
-                                       [j_1, j_2, j_3, m_1, m_2, m_3])
+    j_1, j_2, j_3, m_1, m_2, m_3 = \
+        map(_int_or_halfint, map(sympify,
+            [j_1, j_2, j_3, m_1, m_2, m_3]))
 
     if m_1 + m_2 + m_3 != 0:
         return S.Zero


Test patch:
diff --git a/sympy/physics/tests/test_clebsch_gordan.py b/sympy/physics/tests/test_clebsch_gordan.py
index 02a8d81936..2085d4a134 100644
--- a/sympy/physics/tests/test_clebsch_gordan.py
+++ b/sympy/physics/tests/test_clebsch_gordan.py
@@ -61,6 +61,9 @@ def test_clebsch_gordan_numpy():
     except ImportError:
         skip("numpy not installed")
     assert clebsch_gordan(*np.zeros(6).astype(np.int64)) == 1
+    assert wigner_3j(2, np.float64(6.0), 4.0, 0, 0, 0) == sqrt(715)/143
+    assert wigner_3j(0, 0.5, 0.5, 0, 0.5, -0.5) == sqrt(2)/2
+    raises(ValueError, lambda: wigner_3j(2.1, 6, 4, 0, 0, 0))
 
 
 def test_wigner():