Repository: sympy/sympy

Issue:
Converting from `numpy.float32(float('inf'))` throws
sympy==1.13.3
numpy==2.1.3
python 3.10.15

```python
import numpy
import sympy
sympy.Float(np.float32(float('inf')))
```
thows with:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.10/site-packages/sympy/core/numbers.py", line 805, in __new__
    num = _convert_numpy_types(num)
  File ".../lib/python3.10/site-packages/sympy/core/sympify.py", line 93, in _convert_numpy_types
    p, q = a.as_integer_ratio()
OverflowError: cannot convert Infinity to integer ratio
```

Discussion:

Patch:
diff --git a/sympy/core/sympify.py b/sympy/core/sympify.py
index 0024d0a70a..716833f15a 100644
--- a/sympy/core/sympify.py
+++ b/sympy/core/sympify.py
@@ -100,9 +100,14 @@ def _convert_numpy_types(a, **sympify_args):
         prec = np.finfo(a).nmant + 1
         # E.g. double precision means prec=53 but nmant=52
         # Leading bit of mantissa is always 1, so is not stored
-        p, q = a.as_integer_ratio()
-        a = mlib.from_rational(p, q, prec)
-        return Float(a, precision=prec)
+        if np.isposinf(a):
+            return Float('inf')
+        elif np.isneginf(a):
+            return Float('-inf')
+        else:
+            p, q = a.as_integer_ratio()
+            a = mlib.from_rational(p, q, prec)
+            return Float(a, precision=prec)
 
 
 @overload


Test patch:
diff --git a/sympy/core/tests/test_sympify.py b/sympy/core/tests/test_sympify.py
index fc87fa4483..40be30c25d 100644
--- a/sympy/core/tests/test_sympify.py
+++ b/sympy/core/tests/test_sympify.py
@@ -883,3 +883,10 @@ def test_issue_21536():
     assert u.is_Add and set(u.args) == {4*x, 2}
     assert v.is_Add and set(v.args) == {6*x, 6}
     assert sympify(["x+3*x+2", "2*x+4*x+2+4"]) == [u, v]
+
+def test_issue_27284():
+    if not numpy:
+        skip("numpy not installed.")
+
+    assert Float(numpy.float32(float('inf'))) == S.Infinity
+    assert Float(numpy.float32(float('-inf'))) == S.NegativeInfinity