Skip to content

expose coordinate padding options in .pad#11213

Draft
ircwaves wants to merge 1 commit intopydata:mainfrom
ircwaves:padding-improvements
Draft

expose coordinate padding options in .pad#11213
ircwaves wants to merge 1 commit intopydata:mainfrom
ircwaves:padding-improvements

Conversation

@ircwaves
Copy link

@ircwaves ircwaves commented Mar 5, 2026

Digging through the backlog with @jsignell, it seems the coord padding with NaN issue comes up every now and again. I've done enough windowed signal processing to know that changing this method's behavior will probably break things for someone, SO this change doesn't break the default type-promotion-and-fill-NaNs behavior. So, I thought I'd put up this PR that extends the change that @TomNicholas suggested as a first draft of what that might look like.

Notes

  1. This keeps the behavior of using the non-coord parameter (end_values, constant_values, etc) values for the coord padding parameters in the case where it is inferred from the data padding mode parameter.
  2. surfaces coord_ prefixed versions of the data padding parameters.

Example runs:

No args da.pad(x=(5,3)):

---------------- initial array ---------------
<xarray.DataArray (x: 3)> Size: 24B
array([0.5, 1.5, 2.5])
Coordinates:
  * x        (x) int64 24B -1 1 3
---------------- call pad ---------------
<xarray.DataArray (x: 11)> Size: 88B
array([nan, nan, nan, nan, nan, 0.5, 1.5, 2.5, nan, nan, nan])
Coordinates:
  * x        (x) float64 88B nan nan nan nan nan -1.0 1.0 3.0 nan nan nan

Or  use the new args for linear ramped coordinates (da.pad(x=(5, 3), constant_values=-1, coord_end_values=compute_end_values(da.indexes["x"], 5, 3), coord_mode="linear_ramp")):

---------------- initial array ---------------
<xarray.DataArray (x: 3)> Size: 24B
array([0.5, 1.5, 2.5])
Coordinates:
  * x        (x) int64 24B -1 1 3
---------------- call pad w/ linear_ramp on coors---------------
<xarray.DataArray (x: 11)> Size: 88B
array([-1. , -1. , -1. , -1. , -1. ,  0.5,  1.5,  2.5, -1. , -1. , -1. ])
Coordinates:
  * x        (x) int64 88B -11 -9 -7 -5 -3 -1 1 3 5 7 9

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.

What should pad do about IndexVariables?

1 participant