xhistogram
xhistogram copied to clipboard
"all arrays must have name"
Hi all,
I really appreciate this package, thanks for putting it together!
I am just playing around with it currently, and I keep getting an error message "all arrays must have name" when I play with my data inside the histogram function. Example screenshot below. Would it be an idea to have an option to plot the histogram without the name of the array, so that the code below works? Especially since I can manipulate the x-label after plotting. It would really help for some quick checks without having to redefine an array with a name every time I perform a manipulation on the data (which might be just for testing purposes).
bins = np.linspace(-800, 0, 16)
h_chi = histogram(ds_chi.Jq.isel(timeSeries=2).rolling(time=24*5).mean(dim='time'), bins=[bins], name='test')
h_chi.plot()
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-90-c6841c4a53fa> in <module>
1 bins = np.linspace(-800, 0, 16)
----> 2 h_chi = histogram(ds_chi.Jq.isel(timeSeries=2).rolling(time=24*5).mean(dim='time'), bins=[bins])
3 h_chi.plot()
~/miniconda3/envs/dcpy/lib/python3.8/site-packages/xhistogram/xarray.py in histogram(bins, dim, weights, density, block_size, bin_dim_suffix, bin_edge_suffix, *args)
78 for a in args:
79 # TODO: make this a more robust check
---> 80 assert a.name is not None, 'all arrays must have a name'
81
82 # we drop coords to simplify alignment
AssertionError: all arrays must have a name
Another option of course is to not have the name dropped by xarray when I do a rolling mean.. But I have a feeling the change here might be easier?!

Hi @ALDepp - thanks a lot for your suggestion! (And sorry it has taken so long to get back to you.)
The reason we require a name is that we use it to determine the name of the output dimension.
Adding a name to a dataarray is as simple as adding .rename('my_name'). So for example,
ds_chi.Jq.isel(timeSeries=2).rolling(time=24*5).mean(dim='time').rename('Jq')
This is a simple workaround. Would it solve your problem?
could add the rename function to the code base
I think that the .rename() workaround is enough. I could add this to the documentation if needed, otherwise, we could close this issue?