Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contourf (and other) plotting fails with newer xarray versions and chunks argument #117

Closed
veenstrajelmer opened this issue Jul 7, 2023 · 0 comments · Fixed by #118
Closed

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Jul 7, 2023

In issue #78 (21cb424) there was a fix for newer xarray versions. When plotting a dataset that was opened with a chunks argument, an error was raised: "KeyError: 'Indexing with a boolean dask array is not allowed. This will result in a dask array of unknown shape. Such arrays are unsupported by Xarray.Please compute the indexer first using .compute()'". This was solved for uda.ugrid.plot(), but not for other plot methods. For instance uda.ugrid.plot.contourf() still fails.

This should be a useful testcase to add (copied and edited from the one that was added in the fixing commit):

def test_plot_with_chunks(self, tmp_path):
    time = xr.DataArray([0.0, 1.0, 2.0], coords={"time": [0, 1, 2]})
    uda = (self.uda * time).transpose()
    uda.name = "test"

    path = tmp_path / "test.nc"
    uda.ugrid.to_netcdf(path)
    back = xugrid.open_dataarray(path, chunks={"time": 1})
    primitive = back.isel(time=0).ugrid.plot.contourf()
    assert primitive is not None

My suggestion is to add darray = darray.squeeze().compute() that was added to plot() one level higher, so to _PlotMethods.__init__. There might be something I am overlooking here

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 a pull request may close this issue.

1 participant