Skip to content

fix bugs in is_scalar and as_variable for dask arrays#1685

Merged
jhamman merged 5 commits intopydata:masterfrom
jhamman:fix/1684
Nov 5, 2017
Merged

fix bugs in is_scalar and as_variable for dask arrays#1685
jhamman merged 5 commits intopydata:masterfrom
jhamman:fix/1684

Conversation

@jhamman
Copy link
Copy Markdown
Member

@jhamman jhamman commented Nov 3, 2017

xref: #1674

cc @shoyer, @mrocklin

getattr(value, 'ndim', None) == 0 or
isinstance(value, (basestring, bytes_type)) or not
isinstance(value, Iterable))
isinstance(value, (Iterable, dask_array_type)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What would be a preferable fix here? It may be worth going back and seeing what the numpy array track is in as_variable.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can just be obj.name is not None (since these objects are guaranteed to have name attributes)

@jhamman jhamman merged commit acae757 into pydata:master Nov 5, 2017
@jhamman jhamman deleted the fix/1684 branch November 5, 2017 01:29
@fmaussion fmaussion modified the milestone: 0.10 Nov 5, 2017
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.

3 participants