def _sort_index(xa: xr.DataArray, copy: bool = True) -> xr.DataArray:
        """Sorts an xarray by its time dimension index (only if it is not already monotonically increasing)."""
        time_dim = xa.dims[0]
        return (
            (xa.copy() if copy else xa)
            if xa.get_index(time_dim).is_monotonic_increasing
            else xa.sortby(time_dim)
        )
Sorts an xarray by its time dimension index (only if it is not already monotonically increasing).
darts/timeseries.py