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

fix bugs in is_scalar and as_variable for dask arrays #1685

Merged
merged 5 commits into from
Nov 5, 2017
Merged

fix bugs in is_scalar and as_variable for dask arrays #1685

merged 5 commits into from
Nov 5, 2017

Conversation

jhamman
Copy link
Member

@jhamman jhamman commented Nov 3, 2017

xref: #1674

cc @shoyer, @mrocklin

@@ -188,7 +189,7 @@ def is_scalar(value):
return (
getattr(value, 'ndim', None) == 0 or
isinstance(value, (basestring, bytes_type)) or not
isinstance(value, Iterable))
isinstance(value, (Iterable, dask_array_type)))
Copy link
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
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.

@@ -94,7 +94,8 @@ def as_variable(obj, name=None):
'{}'.format(obj))
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
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.

@@ -94,7 +94,8 @@ def as_variable(obj, name=None):
'{}'.format(obj))
elif utils.is_scalar(obj):
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
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