Repository: scipy/scipy

Issue:
DEP: raise on >1-dim inputs for optimize.minimize 
Follow-up to https://github.com/scipy/scipy/pull/15297 (as well as #15739 and https://github.com/scipy/scipy/pull/15804): raise error for 1.11


Discussion:
Note: not actionable until we're starting to develop for 1.11.0

Resolving patch:
diff --git a/scipy/optimize/_minimize.py b/scipy/optimize/_minimize.py
--- a/scipy/optimize/_minimize.py
+++ b/scipy/optimize/_minimize.py
@@ -515,11 +515,7 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
     x0 = np.atleast_1d(np.asarray(x0))
 
     if x0.ndim != 1:
-        message = ('Use of `minimize` with `x0.ndim != 1` is deprecated. '
-                   'Currently, singleton dimensions will be removed from '
-                   '`x0`, but an error will be raised in SciPy 1.11.0.')
-        warn(message, DeprecationWarning, stacklevel=2)
-        x0 = np.atleast_1d(np.squeeze(x0))
+        raise ValueError("'x0' must only have one dimension.")
 
     if x0.dtype.kind in np.typecodes["AllInteger"]:
         x0 = np.asarray(x0, dtype=float)


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
@@ -79,13 +79,11 @@ def c3(w):
         cons = ({'type': 'ineq', 'fun': c1},
                 {'type': 'ineq', 'fun': c2},
                 {'type': 'ineq', 'fun': c3})
-        w0 = np.zeros((10, 1))
-        message = 'Use of `minimize` with `x0.ndim != 1` is deprecated.'
-        with pytest.warns(DeprecationWarning, match=message):
-            sol = minimize(f, w0, method='cobyla', constraints=cons,
-                           options={'catol': 1e-6})
-            assert_(sol.maxcv > 1e-6)
-            assert_(not sol.success)
+        w0 = np.zeros((10,))
+        sol = minimize(f, w0, method='cobyla', constraints=cons,
+                       options={'catol': 1e-6})
+        assert_(sol.maxcv > 1e-6)
+        assert_(not sol.success)
 
 
 def test_vector_constraints():
diff --git a/scipy/optimize/tests/test_optimize.py b/scipy/optimize/tests/test_optimize.py
--- a/scipy/optimize/tests/test_optimize.py
+++ b/scipy/optimize/tests/test_optimize.py
@@ -1484,6 +1484,11 @@ def test_duplicate_evaluations(self, method):
                 raise RuntimeError(
                     "Duplicate evaluations made by {}".format(method))
 
+    def test_ndim_error(self):
+        msg = "'x0' must only have one dimension."
+        with assert_raises(ValueError, match=msg):
+            optimize.minimize(lambda x: x, np.ones((2, 1)))
+
 
 @pytest.mark.parametrize(
     'method',
diff --git a/scipy/optimize/tests/test_tnc.py b/scipy/optimize/tests/test_tnc.py
--- a/scipy/optimize/tests/test_tnc.py
+++ b/scipy/optimize/tests/test_tnc.py
@@ -128,13 +128,11 @@ def test_minimize_tnc1(self):
         assert_equal(len(iterx), res.nit)
 
     def test_minimize_tnc1b(self):
-        x0, bnds = matrix([-2, 1]), ([-np.inf, None],[-1.5, None])
+        x0, bnds = np.array([-2, 1]), ([-np.inf, None], [-1.5, None])
         xopt = [1, 1]
-        message = 'Use of `minimize` with `x0.ndim != 1` is deprecated.'
-        with pytest.warns(DeprecationWarning, match=message):
-            x = optimize.minimize(self.f1, x0, method='TNC',
-                                  bounds=bnds, options=self.opts).x
-            assert_allclose(self.f1(x), self.f1(xopt), atol=1e-4)
+        x = optimize.minimize(self.f1, x0, method='TNC',
+                              bounds=bnds, options=self.opts).x
+        assert_allclose(self.f1(x), self.f1(xopt), atol=1e-4)
 
     def test_minimize_tnc1c(self):
         x0, bnds = [-2, 1], ([-np.inf, None],[-1.5, None])