Repository: PlasmaPy/PlasmaPy

Issue:
Remove upper limit on version of SciPy and fix resulting test failures
In #2472, updating to `scipy == 1.12.0` led to four new errors in `test_grids.py`.  I'm not sure what the cause is, but it'd be worth reading through the [release notes for SciPy 1.12.0](https://docs.scipy.org/doc/scipy/release/1.12.0-notes.html).  It'd be really helpful to get this fixed before releasing `2024.1.0` next week.  

The errors are:

```
__________________________________ test_nonuniform_cartesian_NN_interp[pos0-quantities0-expected0] __________________________________
tests/test_grids.py:710: in test_nonuniform_cartesian_NN_interp
pout = nonuniform_cartesian_grid.nearest_neighbor_interpolator(pos, *quantities)
../utils/decorators/helpers.py:58: in wrapper
return f(*bound_args.args, **bound_args.kwargs)
grids.py:1423: in nearest_neighbor_interpolator
vals = self._interp_quantities[i, :]
E   IndexError: arrays used as indices must be of integer (or boolean) type
__________________________________ test_nonuniform_cartesian_NN_interp[pos1-quantities1-expected1] __________________________________
tests/test_grids.py:710: in test_nonuniform_cartesian_NN_interp
pout = nonuniform_cartesian_grid.nearest_neighbor_interpolator(pos, *quantities)
../utils/decorators/helpers.py:58: in wrapper
return f(*bound_args.args, **bound_args.kwargs)
grids.py:1423: in nearest_neighbor_interpolator
vals = self._interp_quantities[i, :]
E   IndexError: arrays used as indices must be of integer (or boolean) type
__________________________________ test_nonuniform_cartesian_NN_interp[pos2-quantities2-expected2] __________________________________
tests/test_grids.py:710: in test_nonuniform_cartesian_NN_interp
pout = nonuniform_cartesian_grid.nearest_neighbor_interpolator(pos, *quantities)
../utils/decorators/helpers.py:58: in wrapper
return f(*bound_args.args, **bound_args.kwargs)
grids.py:1423: in nearest_neighbor_interpolator
vals = self._interp_quantities[i, :]
E   IndexError: arrays used as indices must be of integer (or boolean) type
______________________________________ test_nonuniform_cartesian_nearest_neighbor_interpolator ______________________________________
tests/test_grids.py:736: in test_nonuniform_cartesian_nearest_neighbor_interpolator
pout = grid.nearest_neighbor_interpolator(pos, "x", persistent=True)
../utils/decorators/helpers.py:58: in wrapper
return f(*bound_args.args, **bound_args.kwargs)
grids.py:1423: in nearest_neighbor_interpolator
vals = self._interp_quantities[i, :]
E   IndexError: arrays used as indices must be of integer (or boolean) type
```


Discussion:

Resolving patch:
diff --git a/plasmapy/plasma/grids.py b/plasmapy/plasma/grids.py
--- a/plasmapy/plasma/grids.py
+++ b/plasmapy/plasma/grids.py
@@ -1393,9 +1393,9 @@ def _nearest_neighbor_interpolator(self):
 
         """
 
-        indgrid = np.arange(self.grid.shape[0])
-
-        return interp.NearestNDInterpolator(self.grid.to(u.m).value, indgrid)
+        return interp.NearestNDInterpolator(
+            self.grid.to(u.m).value, self._interp_quantities
+        )
 
     @modify_docstring(prepend=AbstractGrid.nearest_neighbor_interpolator.__doc__)
     def nearest_neighbor_interpolator(
@@ -1418,10 +1418,6 @@ def nearest_neighbor_interpolator(
         pts1 = self.pts1.to(u.m).value
         pts2 = self.pts2.to(u.m).value
 
-        i = self._nearest_neighbor_interpolator(pos)
-
-        vals = self._interp_quantities[i, :]
-
         mask_particle_off = (
             (pos[:, 0] < pts0.min())
             | (pos[:, 0] > pts0.max())
@@ -1431,6 +1427,7 @@ def nearest_neighbor_interpolator(
             | (pos[:, 2] > pts2.max())
         )
 
+        vals = self._nearest_neighbor_interpolator(pos)
         vals[mask_particle_off] = np.nan
 
         output = [vals[:, arg] * self._interp_units[arg] for arg in range(len(args))]


Test patch: