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

Consistent handling of 0-dimensional XArrays for dtype=object #44

Merged
merged 4 commits into from
Mar 4, 2014

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Mar 4, 2014

Numpy unpacks 0-dimensional ararys when indexed. We should do the same.

Numpy unpacks 0-dimensional ararys when indexed. We should do the same.
@@ -23,9 +23,6 @@ def _as_compatible_data(data):
required = ['dtype', 'shape', 'size', 'ndim']
if not all(hasattr(data, attr) for attr in required):
data = np.asarray(data)
if data.ndim == 0:
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this (and the lines in src/xray/common.py) are the residuals of an old fix I did which turned out to be incomplete. I think it's safer to always guarantee that _data satisfies the nd-array API and then unpack the array if/when the data array is accessed.

@shoyer
Copy link
Member Author

shoyer commented Mar 4, 2014

@akleeman Do these unit tests make more sense? Now everything is explicitly compared against what the ndarray does.

@akleeman
Copy link
Contributor

akleeman commented Mar 4, 2014

Yes much clearer, thanks. As soon as build passes I'll merge it in.

akleeman added a commit that referenced this pull request Mar 4, 2014
Consistent handling of 0-dimensional XArrays for dtype=object
@akleeman akleeman merged commit a82a59b into master Mar 4, 2014
@shoyer shoyer deleted the fix-0d-xarrays branch March 4, 2014 22:45
keewis pushed a commit to keewis/xarray that referenced this pull request Jan 17, 2024
* swapped original init for a .from_dict method

* updated tests

* corrected options for creating datatree objects
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.

None yet

2 participants