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

Dataset.__setitem__ raise on being passed a Dataset (for single key) #5839

Merged
merged 6 commits into from
Oct 23, 2021

Conversation

TomNicholas
Copy link
Contributor

@TomNicholas TomNicholas commented Oct 5, 2021

Inspired by confusion in #5833, this PR slightly clarifies the error thrown when the user attempts to do ds['var'] = xr.Dataset. The original error is

TypeError: cannot directly convert an xarray.Dataset into a numpy array. Instead, create an xarray.DataArray first, either with indexing on the Dataset or by invoking the `to_array()` method.

while the new error is

TypeError: Cannot assign a Dataset to a single key - only a DataArray or Variable object can be stored under a single key.
  • Tests added
  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@TomNicholas TomNicholas changed the title raise on being passed a Dataset Dataset.__setitem__ raise on being passed a Dataset (for single key) Oct 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2021

Unit Test Results

         6 files           6 suites   55m 45s ⏱️
16 226 tests 14 490 ✔️ 1 736 💤 0
90 552 runs  82 371 ✔️ 8 181 💤 0

Results for commit 119864d.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TomNicholas TomNicholas merged commit 214bbe0 into pydata:main Oct 23, 2021
snowman2 pushed a commit to snowman2/xarray that referenced this pull request Feb 9, 2022
…ydata#5839)

* raise on being passed a Dataset

* linting

* added a test

* whatsnew

* linting

* clearer grammar in error message
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 this pull request may close these issues.

2 participants