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

Unable to run example for xarray.DataArray.to_unstacked_dataset #3148

Closed
TalfanBarnie opened this issue Jul 19, 2019 · 9 comments
Closed

Unable to run example for xarray.DataArray.to_unstacked_dataset #3148

TalfanBarnie opened this issue Jul 19, 2019 · 9 comments

Comments

@TalfanBarnie
Copy link

Hello,

When I try to run the example for
xarray.DataArray.to_unstacked_dataset

I get the error:

Traceback (most recent call last):
File "", line 1, in
File "/home/talfan/anaconda3/envs/to_unstacked/lib/python3.7/site-packages/xarray/core/dataset.py", line 2915, in to_stacked_array
"dimensions {}.".format(dims)
ValueError: All variables in the dataset must contain the dimensions ('x',).

when running the line
stacked = data.to_stacked_array("z", ['y'])

This is my setup:

pip freeze
certifi==2019.6.16
numpy==1.16.4
pandas==0.25.0
python-dateutil==2.8.0
pytz==2019.1
six==1.12.0
xarray==0.12.3+20.g9afe4d0c

Any idea what might be going wrong?

Many thanks for your help!

@shoyer
Copy link
Member

shoyer commented Jul 21, 2019

There's a typo in the docstring example. It should be data.to_stacked_array("z", ['x']).

@shoyer
Copy link
Member

shoyer commented Jul 21, 2019

cc @nbren12

@nbren12
Copy link
Contributor

nbren12 commented Jul 21, 2019

Huh, it looks like that change in the API that happened in the last stages of the PR didn't make it into the example docs. I will try to submit a PR fixing that sometime soon.

@nbren12
Copy link
Contributor

nbren12 commented Jul 21, 2019

Actually, the docs seem correct:

>>> data.to_stacked_array("z", sample_dims=['x'])

Am I missing something here?

@TalfanBarnie
Copy link
Author

The correction works, many thanks. The incorrect version is still on http://xarray.pydata.org/en/stable/, maybe that needs to be updated somehow?

@nbren12
Copy link
Contributor

nbren12 commented Jul 22, 2019

Could you link the specific page that is wrong?

@TalfanBarnie
Copy link
Author

It's here:

http://xarray.pydata.org/en/stable/generated/xarray.DataArray.to_unstacked_dataset.html#xarray.DataArray.to_unstacked_dataset

Under examples the line that reads:

stacked = data.to_stacked_array("z", ['y'])

should read

data.to_stacked_array("z", ['x'])

Thanks for looking into it!

@nbren12
Copy link
Contributor

nbren12 commented Jul 22, 2019

Okay. it looks like the docstring for to_unstacked_dataset is in fact incorrect:

>>> stacked = data.to_stacked_array("z", ['y'])

I will can submit a PR fixing that soon.

@keewis
Copy link
Collaborator

keewis commented Feb 19, 2021

it looks like this should have been closed by #4408

@keewis keewis closed this as completed Feb 19, 2021
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

No branches or pull requests

4 participants