Repository: scipy/scipy

Issue:
minimize_cobyla broken if `disp=True` passed
7819b7f removed the deprecated `iprint` argument from `optimize.cobyla`.  However, it did not do so completely.  If `disp=False` is passed to minimize, then some left-over code referencing `iprint` sets `iprint=0`.  If `disp=True`, the converse is not true (iprint is left unbound).  Later, `iprint` is unconditionally referenced.

c.f.
https://github.com/scipy/scipy/blob/master/scipy/optimize/cobyla.py#L200 sets iprint=0 if not disp.  But https://github.com/scipy/scipy/blob/master/scipy/optimize/cobyla.py#L252 references iprint anyway.

### Reproducing code example:
```python
import scipy.optimize
def f(x): return sum(_**2 for _ in x)
scipy.optimize.minimize(f, [1], method="cobyla", options=dict(disp=True))
```

### Error message:
```python
>>> scipy.optimize.minimize(f, [1], method="cobyla", options=dict(disp=True))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/lmitche1/src/firedrake/lib/python3.5/site-packages/scipy/optimize/_minimize.py", line 492, in minimize
    return _minimize_cobyla(fun, x0, args, constraints, **options)
  File "/data/lmitche1/src/firedrake/lib/python3.5/site-packages/scipy/optimize/cobyla.py", line 252, in _minimize_cobyla
    rhoend=rhoend, iprint=iprint, maxfun=maxfun,
UnboundLocalError: local variable 'iprint' referenced before assignment
>>> 
```

### Scipy/Numpy/Python version information:
```python
>>> import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.0.0 1.13.3 sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
```




Discussion:
On 1.0.0 a previously-passing example now fails on CircleCI for me with a similar traceback:
```
  File "/home/ubuntu/mne-python/mne/bem.py", line 994, in _fit_sphere
    rhoend=radius_init * 1e-6, disp=disp)
  File "/home/ubuntu/miniconda/envs/mne27/lib/python2.7/site-packages/scipy/optimize/cobyla.py", line 167, in fmin_cobyla
    **opts)
  File "/home/ubuntu/miniconda/envs/mne27/lib/python2.7/site-packages/scipy/optimize/cobyla.py", line 252, in _minimize_cobyla
    rhoend=rhoend, iprint=iprint, maxfun=maxfun,
UnboundLocalError: local variable 'iprint' referenced before assignment
```
So I can confirm that this behavior. It makes sense from looking at the code, too, I think. I'll try to come up with a PR quickly unless someone else beats me to it.

Resolving patch:
diff --git a/scipy/optimize/cobyla.py b/scipy/optimize/cobyla.py
--- a/scipy/optimize/cobyla.py
+++ b/scipy/optimize/cobyla.py
@@ -196,8 +196,7 @@ def _minimize_cobyla(fun, x0, args=(), constraints=(),
     _check_unknown_options(unknown_options)
     maxfun = maxiter
     rhoend = tol
-    if not disp:
-        iprint = 0
+    iprint = int(bool(disp))
 
     # check constraints
     if isinstance(constraints, dict):


Test patch:
diff --git a/scipy/optimize/tests/test_cobyla.py b/scipy/optimize/tests/test_cobyla.py
--- a/scipy/optimize/tests/test_cobyla.py
+++ b/scipy/optimize/tests/test_cobyla.py
@@ -25,8 +25,9 @@ def con2(self, x):
         return -self.con1(x)
 
     def test_simple(self):
+        # use disp=True as smoke test for gh-8118
         x = fmin_cobyla(self.fun, self.x0, [self.con1, self.con2], rhobeg=1,
-                        rhoend=1e-5, maxfun=100)
+                        rhoend=1e-5, maxfun=100, disp=True)
         assert_allclose(x, self.solution, atol=1e-4)
 
     def test_minimize_simple(self):