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

"all arrays must have name" #23

Open
ALDepp opened this issue Oct 9, 2020 · 3 comments · May be fixed by #85
Open

"all arrays must have name" #23

ALDepp opened this issue Oct 9, 2020 · 3 comments · May be fixed by #85

Comments

@ALDepp
Copy link

ALDepp commented Oct 9, 2020

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?!

image

@rabernat
Copy link
Contributor

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?

@raybellwaves
Copy link
Contributor

could add the rename function to the code base

@iuryt
Copy link

iuryt commented Oct 10, 2023

I think that the .rename() workaround is enough. I could add this to the documentation if needed, otherwise, we could close this issue?

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.

4 participants