Repository: sympy/sympy

Issue:
lambdify(sympy.abc.a, sympy.abc.a / 0 , "numpy") gives NameError
When using `lambdify(...)` with `"numpy"` as the module, if the expression involves the complex infinity `zoo` symbol then the result cannot subsequently be evaluated because a NameError is thrown.

A minimum working example:
```python
import sympy
import sympy.abc

expr = sympy.abc.a / 0
func = sympy.lambdify(sympy.abc.a, expr, "numpy")
eval_func = func(1)

print eval_func
```
gives
```
NameError: global name 'zoo' is not defined
```
from the line `eval_func = func(1)`.

Note that if `expr = sympy.oo` or `expr = sympy.oo * sympy.abc.a` instead, we get `inf` as the result; this makes sense.

This unhandled exception can be avoided by doing
```python
from sympy.utilities.lambdify import NUMPY_TRANSLATIONS
NUMPY_TRANSLATIONS["zoo"] = "nan"
```
first, which ensures `sympy` can map the `zoo` in the same way it already maps `oo`. The issue is what exactly `zoo` should map to and whether `nan` is appropriate, which may explain why it has not been mapped already? Since `numpy` has no corresponding complex infinity, surely `nan` is better than an unhandled exception?

Discussion:

Patch:
diff --git a/sympy/printing/pycode.py b/sympy/printing/pycode.py
index 7830ebbde2..9cac9b5f84 100644
--- a/sympy/printing/pycode.py
+++ b/sympy/printing/pycode.py
@@ -128,6 +128,12 @@ def _print_sign(self, e):
         return '(0.0 if {e} == 0 else {f}(1, {e}))'.format(
             f=self._module_format('math.copysign'), e=self._print(e.args[0]))
 
+    def _print_NegativeInfinity(self, expr):
+        return "float('-inf')"
+
+    def _print_ComplexInfinity(self, expr):
+        return self._print_NaN(expr)
+
     def _print_Mod(self, expr):
         PREC = precedence(expr)
         return ('{0} % {1}'.format(*map(lambda x: self.parenthesize(x, PREC), expr.args)))


Test patch:
diff --git a/sympy/printing/tests/test_pycode.py b/sympy/printing/tests/test_pycode.py
index d70a63d0ae..f5fb800636 100644
--- a/sympy/printing/tests/test_pycode.py
+++ b/sympy/printing/tests/test_pycode.py
@@ -2,8 +2,9 @@
 from __future__ import (absolute_import, division, print_function)
 
 from sympy.codegen import Assignment
-from sympy.core import Expr, Mod, symbols, Eq, Le, Gt
+from sympy.core import Expr, Mod, symbols, Eq, Le, Gt, zoo, oo
 from sympy.core.numbers import pi
+from sympy.external import import_module
 from sympy.logic import And, Or
 from sympy.functions import acos, Piecewise, sign
 from sympy.matrices import SparseMatrix
@@ -76,3 +77,9 @@ def test_printmethod():
     obj = CustomPrintedObject()
     assert NumPyPrinter().doprint(obj) == 'numpy'
     assert MpmathPrinter().doprint(obj) == 'mpmath'
+
+def test_issue_14283():
+    prntr = PythonCodePrinter()
+
+    assert prntr.doprint(zoo) == "float('nan')"
+    assert prntr.doprint(-oo) == "float('-inf')"