Skip to content

error when using broadcast_arrays with coordinates #649

Description

@rabernat

I frequently use broadcast_arrays to to feed xray variables to non-xray libraries (e.g. gsw.) Often I need to broadcast the coordinates and variables in order to do call functions that take both as arguments.

I have found that broadcast_arrays doesn't work as I expect with coordinates. For example

import xray
import numpy as np
ds = xray.Dataset({'a': (['y','x'], np.ones((20,10)))},
                  coords={'x': (['x'], np.arange(10)),
                          'y': (['y'], np.arange(20))})
xbc, ybc, abc = xray.broadcast_arrays(ds.x, ds.y, ds.a)

This raises ValueError: an index variable must be defined with 1-dimensional data.

If I change the last line to

xbc, ybc, abc = xray.broadcast_arrays(1*ds.x, 1*ds.y, ds.a)

it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions