fix bugs in is_scalar and as_variable for dask arrays#1685
fix bugs in is_scalar and as_variable for dask arrays#1685jhamman merged 5 commits intopydata:masterfrom jhamman:fix/1684
Conversation
xarray/core/utils.py
Outdated
| getattr(value, 'ndim', None) == 0 or | ||
| isinstance(value, (basestring, bytes_type)) or not | ||
| isinstance(value, Iterable)) | ||
| isinstance(value, (Iterable, dask_array_type))) |
There was a problem hiding this comment.
dask_array_type is actually a tuple, so this needs to be (Iterable,) + dask_array_type.
That said... this already tricky logic is getting even more convoluted. So this isn't my favorite fix, though I agree that an N-dimensional dask array should not be considered a scalar.
There was a problem hiding this comment.
What would be a preferable fix here? It may be worth going back and seeing what the numpy array track is in as_variable.
xarray/core/variable.py
Outdated
| elif utils.is_scalar(obj): | ||
| obj = Variable([], obj) | ||
| elif getattr(obj, 'name', None) is not None: | ||
| elif (getattr(obj, 'name', None) is not None and not |
There was a problem hiding this comment.
Instead, let's call out the types from which we can safely get the name for the dimension (there are likely to be other types that reuse name). I think that's IndexVariable and pandas.Index.
xarray/core/variable.py
Outdated
| obj = Variable([], obj) | ||
| elif getattr(obj, 'name', None) is not None: | ||
| elif (isinstance(obj, (pd.Index, IndexVariable)) and | ||
| getattr(obj, 'name', None) is not None): |
There was a problem hiding this comment.
This can just be obj.name is not None (since these objects are guaranteed to have name attributes)
git diff upstream/master **/*py | flake8 --diffwhats-new.rstfor all changes andapi.rstfor new APIxref: #1674
cc @shoyer, @mrocklin