Repository: sympy/sympy

Issue:
CI failure: lambdify: NameError: name 'polygamma' is not defined
This failure is seen in CI for the 3.11 optional dependency tests:
```
____________ sympy/utilities/tests/test_lambdify.py:test_scipy_fns _____________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/utilities/tests/test_lambdify.py", line 1103, in test_scipy_fns
    assert abs(f(tv) - sympy_result) < 1e-13*(1 + abs(sympy_result))
               ^^^^^
  File "<lambdifygenerated-604>", line 2, in _lambdifygenerated
    return polygamma(0, x)
           ^^^^^^^^^
NameError: name 'polygamma' is not defined
```
That CI job uses latest cython, numpy and scipy from git so this is likely due to a change in scipy.

Discussion:

Patch:
diff --git a/sympy/printing/numpy.py b/sympy/printing/numpy.py
index 5ab29585a1..a42d1df5d2 100644
--- a/sympy/printing/numpy.py
+++ b/sympy/printing/numpy.py
@@ -290,6 +290,7 @@ def _print_NDimArray(self, expr):
     'gamma': 'gamma',
     'loggamma': 'gammaln',
     'digamma': 'psi',
+    'polygamma': 'polygamma',
     'RisingFactorial': 'poch',
     'jacobi': 'eval_jacobi',
     'gegenbauer': 'eval_gegenbauer',


Test patch:
diff --git a/sympy/printing/tests/test_numpy.py b/sympy/printing/tests/test_numpy.py
index 7b83e2a4f6..6e7e6b71e5 100644
--- a/sympy/printing/tests/test_numpy.py
+++ b/sympy/printing/tests/test_numpy.py
@@ -1,8 +1,10 @@
 from sympy.concrete.summations import Sum
 from sympy.core.mod import Mod
 from sympy.core.relational import (Equality, Unequality)
+from sympy.core.symbol import Symbol
 from sympy.functions.elementary.miscellaneous import sqrt
 from sympy.functions.elementary.piecewise import Piecewise
+from sympy.functions.special.gamma_functions import polygamma
 from sympy.matrices.expressions.blockmatrix import BlockMatrix
 from sympy.matrices.expressions.matexpr import MatrixSymbol
 from sympy.matrices.expressions.special import Identity
@@ -341,3 +343,6 @@ def test_scipy_print_methods():
     assert hasattr(prntr, '_print_erf')
     assert hasattr(prntr, '_print_factorial')
     assert hasattr(prntr, '_print_chebyshevt')
+    k = Symbol('k', integer=True, nonnegative=True)
+    x = Symbol('x', real=True)
+    assert prntr.doprint(polygamma(k, x)) == "scipy.special.polygamma(k, x)"
diff --git a/sympy/utilities/tests/test_lambdify.py b/sympy/utilities/tests/test_lambdify.py
index 50b2857118..757219c85a 100644
--- a/sympy/utilities/tests/test_lambdify.py
+++ b/sympy/utilities/tests/test_lambdify.py
@@ -23,7 +23,7 @@
 from sympy.functions.special.beta_functions import (beta, betainc, betainc_regularized)
 from sympy.functions.special.delta_functions import (Heaviside)
 from sympy.functions.special.error_functions import (Ei, erf, erfc, fresnelc, fresnels)
-from sympy.functions.special.gamma_functions import (digamma, gamma, loggamma)
+from sympy.functions.special.gamma_functions import (digamma, gamma, loggamma, polygamma)
 from sympy.integrals.integrals import Integral
 from sympy.logic.boolalg import (And, false, ITE, Not, Or, true)
 from sympy.matrices.expressions.dotproduct import DotProduct
@@ -1080,7 +1080,7 @@ def test_scipy_fns():
     single_arg_sympy_fns = [Ei, erf, erfc, factorial, gamma, loggamma, digamma]
     single_arg_scipy_fns = [scipy.special.expi, scipy.special.erf, scipy.special.erfc,
         scipy.special.factorial, scipy.special.gamma, scipy.special.gammaln,
-        scipy.special.psi]
+                            scipy.special.psi]
     numpy.random.seed(0)
     for (sympy_fn, scipy_fn) in zip(single_arg_sympy_fns, single_arg_scipy_fns):
         f = lambdify(x, sympy_fn(x), modules="scipy")
@@ -1104,18 +1104,20 @@ def test_scipy_fns():
             assert abs(f(tv) - scipy_fn(tv)) < 1e-13*(1 + abs(sympy_result))
 
     double_arg_sympy_fns = [RisingFactorial, besselj, bessely, besseli,
-        besselk]
+                            besselk, polygamma]
     double_arg_scipy_fns = [scipy.special.poch, scipy.special.jv,
-        scipy.special.yv, scipy.special.iv, scipy.special.kv]
+                            scipy.special.yv, scipy.special.iv, scipy.special.kv, scipy.special.polygamma]
     for (sympy_fn, scipy_fn) in zip(double_arg_sympy_fns, double_arg_scipy_fns):
         f = lambdify((x, y), sympy_fn(x, y), modules="scipy")
         for i in range(20):
             # SciPy supports only real orders of Bessel functions
             tv1 = numpy.random.uniform(-10, 10)
             tv2 = numpy.random.uniform(-10, 10) + 1j*numpy.random.uniform(-5, 5)
-            # SciPy supports poch for real arguments only
-            if sympy_fn == RisingFactorial:
+            # SciPy requires a real valued 2nd argument for: poch, polygamma
+            if sympy_fn in (RisingFactorial, polygamma):
                 tv2 = numpy.real(tv2)
+            if sympy_fn == polygamma:
+                tv1 = abs(int(tv1))  # first argument to polygamma must be a non-negative integral.
             sympy_result = sympy_fn(tv1, tv2).evalf()
             assert abs(f(tv1, tv2) - sympy_result) < 1e-13*(1 + abs(sympy_result))
             assert abs(f(tv1, tv2) - scipy_fn(tv1, tv2)) < 1e-13*(1 + abs(sympy_result))