Skip to content

Expose coord_mode in .pad() #6425

@jbusecke

Description

@jbusecke

Is your feature request related to a problem?

I am experiencing some issues with the way coordinates are padded. Currently the coordinates are padded according to the mode parameter passed to pad() here. For my particular issue I want to be able to have different modes for the data, but effectively pin the mode that is used to pad the coordinate values.

A simple example:

import xarray as xr
import numpy as np

da = xr.DataArray([1,2,3], dims=['x'], coords={'x':[4,5,6]})
da

image

If I pad with constant

da.pad(x=(0,1), mode='constant')

I get this:
image
which is the coordinate padding I need.

But if I pad with wrap:

da.pad(x=(0,1), mode='wrap')

which gives me repeated coordinate values
image

Describe the solution you'd like

I would like to be able to do something like this:

da.pad(x=(0,1), mode='wrap', coord_pad_mode='constant')

and get something like this
image

Since #3596 internally already defines coord_pad_mode it should be easy enough to expose this to the user?

Possibly related (but I think not incompatible with the changes propsed here?): #3868

Happy to work with @TomNicholas on a PR, but wanted to get some feedback/comments first.

cc @dcherian @mark-boer who worked on this code.

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions