Repository navigation
Accept DataArray target grids - #75
ZackaryLoevseth wants to merge 2 commits into
Conversation
|
Thanks for submitting this PR. The tests are failing due to a problem with github's billing system on the organization. |
|
The re-run's only failures are |
BSchilperoort
left a comment
There was a problem hiding this comment.
#76 fixes the CI issues.
Two comments from me.
| expected = regrid(target.coords.to_dataset(), **kwargs) | ||
| actual = regrid(target, **kwargs) |
There was a problem hiding this comment.
regrid will already do .coords.to_dataset() so this expected test result should always be the same...
There was a problem hiding this comment.
You're right, that comparison could only fail by raising. expected now comes from a Dataset built directly from the coordinate values, and there is a new test with hand-computed values (linear and conservative) for the unnamed-target-with-time case that fails on main.
| if time_dim is not None and time_dim in ds_target_grid.coords: | ||
| ds_target_grid = ds_target_grid.isel({time_dim: 0}).reset_coords() | ||
| target_grid: xr.Dataset = ( | ||
| ds_target_grid.coords.to_dataset() |
There was a problem hiding this comment.
.coords.to_dataset() causes dims without coords to be dropped. This can cause users to get an incorrect error later. Maybe it would be good to check that ds_target_grid has no dims without coords 🤔
There was a problem hiding this comment.
Good catch. A target with dims but no coordinates got "None of the target dims are in the data … Target dims: []" here, where main (and the same grid as a Dataset) reports the missing coords. The dims check now reads the dims from the target before the conversion, so those errors are the same as on main, with a test.
I didn't add a hard check, because DataArray targets with a dim without a coordinate (an extra bnds-like dim, or time without a coordinate) regrid fine on main today, the same as the Dataset holding them, and DataArray.interp_like skips such dims too. Happy to add the check if you prefer it.
Closes #64.
The regridding methods already work with most
xr.DataArraytargets, but an unnamed DataArray target with a time coordinate fails invalidate_input:reset_coords()on an unnamed DataArray raisesValueError: cannot reset_coords with drop=False on an unnamed DataArray. This turns a DataArray target into its coordinates (target.coords.to_dataset()) before validation, so its values are never read, and widens the type hints and docstrings of the seven methods andvalidate_inputtoxr.DataArray | xr.Dataset.As you suggested in the issue, it comes with tests:
tests/test_dataarray_target.pychecks every method with a DataArray target against the same grid as a Dataset (named and unnamed targets, with and without time, NumPy and Dask, DataArray and Dataset input) and checks that a lazy target's values are not computed. 24 of the 97 cases fail on main and all pass with the change. The twotest_conservative_nan_thresholds_against_coarsenfailures on main come from xarray'scoarsen(skipna=...)and are unchanged.