Skip to content

Do not add a coordinate to the input in resample_iterations_idx - #489

Open
ZackaryLoevseth wants to merge 1 commit into
xarray-contrib:mainfrom
ZackaryLoevseth:fix/resample-input-mutation
Open

ZackaryLoevseth wants to merge 1 commit into
xarray-contrib:mainfrom
ZackaryLoevseth:fix/resample-input-mutation

Conversation

@ZackaryLoevseth

Copy link
Copy Markdown

Description

When the resampled dimension has no coordinate, resample_iterations_idx sets one with forecast.coords[dim] = np.arange(...), which modifies the caller's object: after the call the input has a new dim coordinate. This uses assign_coords, which returns a new object, instead. The output is unchanged.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The new test calls both resampling functions twice (1 and 2 iterations; DataArray and Dataset; NumPy and Dask) and checks that the input is unchanged and that the output has no dim coordinate. The 8 resample_iterations_idx cases fail on main and pass with the fix; the full test suite passes.

Checklist (while developing)

  • Tests added for pytest, if necessary.

When the resampled dimension had no coordinate, the function assigned
one with forecast.coords[dim] = ..., which changed the caller's object.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant