Skip to content

dask.array renaming creates ValueError #7209

Closed

Description

@patquem

Hello,

I report you a strange behaviour I observe when trying to rename a dask.array data field.
In the following script, I want to delete the default data name ('map_data_frame...') in the colormap when plotting.
when uncommenting the COMMENT-2 : it's ok
But when uncommenting the COMMENT-1 (this only one), I generate the following error message :
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (4,) and requested shape (1,10,10)

strange, isn't it ?

Patrick

import numpy as np
from PIL import Image
from dask_image.imread import imread
import xarray as xr
import matplotlib.pyplot as plt

for i in range(10):
    arr = i * np.ones((10, 10))
    img = Image.fromarray(arr)
    img.save(f'img_{i}.tif')

darr = imread('*.tif')
# darr.name = None  # COMMENT-1
x = y = z = np.arange(10)
xarr = xr.DataArray(darr, coords=[('z', z), ('y', y), ('x', x)])
# xarr.name = None # COMMENT-2

print(xarr.name)
xarr.to_netcdf("test.nc")

xarr.isel(x=5).plot()
plt.show()

Activity

  1. jsignell commented on Feb 12, 2021

    @jsignell
    Member

    I tham wondering why you are trying to set the name of the dask.array. It seems like the dask.array.name is a special property that is expected to have certain features. Changing the name of the array will have unintended consequences.

    That being said, there is probably something we can do in dask to protect people from inadvertently setting the name to something invalid.

  2. patquem commented on Feb 15, 2021

    @patquem
    ContributorAuthor

    Hello @jsignell ,

    As explained above, colormap with label named '_map_read_frame-ca2cc3dd7ed112e69d4a351f0b358663' was not very relevant in my case.

    I tried First to change this by renaming the dask.array.name (associated to the previous label) And I found really strange that changing the name engendered such a misbehaviour.

    On my mind, this shouldn't - like what is obtained when doing xarray.name renaming.
    Dask.array.name should be 'just' a name (used for labelling for instance) and it shouldn't be responsible of this :
    ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (4,) and requested shape (1,10,10)
    But this is just my opinion :)

    Patrick

  3. jsignell commented on Feb 15, 2021

    @jsignell
    Member

    In dask.array name is not user-facing in the way that it is in xarray.DataArray. If you want to control the name that shows up on your plot, you should change the name on the xarray object like you do in COMMENT-2.

  4. patquem commented on Feb 17, 2021

    @patquem
    ContributorAuthor

    @jsignell , I have seen the discussion you had with @mrocklin (and your PR).
    That was the aim of my issue.... so I can close it.
    Thanks for all.
    Patrick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions