Repository: scipy/scipy
File: scipy/interpolate/_ndbspline.py (Python)

Code before:
        return new_c, new_t

    def derivative(self, nu):
        """
        Construct a new NdBSpline representing the partial derivative.

        Parameters
        ----------
        nu : array_like of shape (ndim,)
            Orders of the partial derivatives to compute along each dimension.

        Returns
        -------
        NdBSpline
            A new NdBSpline representing the partial derivative of the original spline.

        """
        nu_arr = np.asarray(nu, dtype=np.int64)
        ndim = len(self.t)

        if nu_arr.ndim != 1 or nu_arr.shape[0] != ndim:
            raise ValueError(
                f"invalid number of derivative orders {nu = } for "
                f"ndim = {len(self.t)}.")

        if any(n < 0 for n in nu_arr):
            raise ValueError(f"derivative orders must be positive, got {nu = }")

        t_new = list(self.t)
        k_new = list(self.k)
        c_new = self.c.copy()

        for axis, n in enumerate(nu_arr):
            if n == 0:
                continue

            c_new, t_new[axis] = self._bspline_derivative_along_axis(
                c_new, t_new[axis], k_new[axis], axis, nu=n
            )
            k_new[axis] = max(k_new[axis] - n, 0)

        return NdBSpline(tuple(t_new), c_new,
                         tuple(k_new), extrapolate=self.extrapolate)

def _preprocess_inputs(k, t_tpl):
    """Helpers: validate and preprocess NdBSpline inputs.

       Parameters
       ----------
       k : int or tuple
          Spline orders

Review comment (suggestion):
Sorry not part of your changes but is this not just
```suggestion
        if any(nu_arr < 0):
```

Code after:
        return new_c, new_t

    def derivative(self, nu):
        """
        Construct a new NdBSpline representing the partial derivative.

        Parameters
        ----------
        nu : array_like of shape (ndim,)
            Orders of the partial derivatives to compute along each dimension.

        Returns
        -------
        NdBSpline
            A new NdBSpline representing the partial derivative of the original spline.

        """
        nu_arr = np.asarray(nu, dtype=np.int64)
        ndim = len(self.t)

        if nu_arr.ndim != 1 or nu_arr.shape[0] != ndim:
            raise ValueError(
                f"invalid number of derivative orders {nu = } for "
                f"ndim = {len(self.t)}.")

        if any(nu_arr < 0):
            raise ValueError(f"derivative orders must be positive, got {nu = }")

        t_new = list(self.t)
        k_new = list(self.k)
        c_new = self.c.copy()

        for axis, n in enumerate(nu_arr):
            if n == 0:
                continue

            c_new, t_new[axis] = self._bspline_derivative_along_axis(
                c_new, t_new[axis], k_new[axis], axis, nu=n
            )
            k_new[axis] = max(k_new[axis] - n, 0)

        return NdBSpline(tuple(t_new), c_new,
                         tuple(k_new), extrapolate=self.extrapolate)

def _preprocess_inputs(k, t_tpl):
    """Helpers: validate and preprocess NdBSpline inputs.

       Parameters
       ----------
       k : int or tuple
          Spline orders