Repository: scipy/scipy

Issue:
BUG: RegularGridInterpolator error message is wrong
### Describe your issue.

The regularGridInterpolator checks that the data to be interpolated has the same dimensions as the reference data points.
However if that checks fails, the error message reports the wrong dimensions:

In scipy/interpolate/_rgi.py at line 303

```     ndim = len(self.grid)
        xi = _ndim_coords_from_arrays(xi, ndim=ndim)
        if xi.shape[-1] != len(self.grid):
            raise ValueError("The requested sample points xi have dimension "
                             "%d, but this RegularGridInterpolator has "
                             "dimension %d" % (xi.shape[1], ndim))
```

Last line should be 
` "dimension %d" % (xi.shape[-1], ndim))`

Since the check is on dimension -1, and the number of dimensions of the points to be interpolated is indeed xi.shape[-1]

### Reproducing Code Example

```python
import scipy
from scipy.interpolate import RegularGridInterpolator
data=[[[1.]]]
x=[0]
y=[0]
z=[0]
my_interpolating_function = RegularGridInterpolator((x, y, z), data,bounds_error=False)

my_interpolating_function([[[0.1,0.2]]])
```


### Error message

```shell
Traceback (most recent call last):

  File "/tmp/ipykernel_9436/4103262667.py", line 9, in <module>
    my_interpolating_function([[[0.1,0.2]]])

  File "/home/clement/.local/lib/python3.8/site-packages/scipy/interpolate/_interpolate.py", line 2517, in __call__
    raise ValueError("The requested sample points xi have dimension "

ValueError: The requested sample points xi have dimension 1, but this RegularGridInterpolator has dimension 3
```


### SciPy/NumPy/Python version information

1.8.1 1.21.4 sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0


Discussion:
Would you be interested in submitting a PR with a fix @cm7S ? 
Sure thing!
________________________________
From: Evgeni Burovski ***@***.***>
Sent: Thursday, June 9, 2022 6:31 PM
To: scipy/scipy ***@***.***>
Cc: Clement Marti ***@***.***>; Mention ***@***.***>
Subject: Re: [scipy/scipy] BUG: RegularGridInterpolator error message is wrong (Issue #16380)


Would you be interested in submitting a PR with a fix @cm7S<https://github.com/cm7S> ?

—
Reply to this email directly, view it on GitHub<https://github.com/scipy/scipy/issues/16380#issuecomment-1151350969>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AZR3HPTHUIVBS552MTZDWX3VOIL4TANCNFSM5YKIPDYQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>


Resolving patch:
diff --git a/scipy/interpolate/_rgi.py b/scipy/interpolate/_rgi.py
--- a/scipy/interpolate/_rgi.py
+++ b/scipy/interpolate/_rgi.py
@@ -304,8 +304,8 @@ def __call__(self, xi, method=None):
         xi = _ndim_coords_from_arrays(xi, ndim=ndim)
         if xi.shape[-1] != len(self.grid):
             raise ValueError("The requested sample points xi have dimension "
-                             "%d, but this RegularGridInterpolator has "
-                             "dimension %d" % (xi.shape[1], ndim))
+                             f"{xi.shape[-1]} but this "
+                             f"RegularGridInterpolator has dimension {ndim}")
 
         xi_shape = xi.shape
         xi = xi.reshape(-1, xi_shape[-1])


Test patch: