Skip to content

Unstacking produces flipped array when using decreasing coordinate values #980

Closed
@shoyer

Description

@shoyer

As reported by @robintw on the mailing list:

If we create a DataArray with the y co-ordinates decreasing:

da = xr.DataArray(np.random.rand(3, 4), dims = ('y', 'x'),
                  coords={'x': np.arange(4),
                          'y': np.arange(3, 0, -1)})

and then stack it and unstack it again:

stacked = da.stack(allpoints=['y', 'x'])
result = stacked.unstack('allpoints')

We find that the top-left value of the resulting array is not the same as the top-left value of the original array:

da.isel(x=0, y=0) # 0.1143
result.isel(x=0, y=0) # 0.696

However, the value at the 'bottom left' of the array matches the top left of the original array:

result.isel(x=0, y=2) # 0.1143

Replacing the y co-ordinates of da with increasing values gives the correct results:

da.coords['y'] = np.arange(da.coords.y)
da.isel(x=0, y=0) # 0.1143
result.isel(x=0, y=0) # 0.1143

I'm assuming this is unintentional behaviour - at least, I couldn't find anything in the docs about it. Is this meant to happen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions