-
Notifications
You must be signed in to change notification settings - Fork 296
Reverse 2878 #2926
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
Reverse 2878 #2926
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,15 +65,6 @@ def _limited_shape(shape): | |
return tuple(shape) | ||
|
||
|
||
def _getall(a): | ||
res = a[()] | ||
if isinstance(res, ma.core.MaskedConstant): | ||
res = ma.masked_array(res.data, mask=res.mask) | ||
return res | ||
|
||
_getall_delayed = dask.delayed(_getall) | ||
|
||
|
||
def as_lazy_data(data, chunks=None, asarray=False): | ||
""" | ||
Convert the input array `data` to a dask array. | ||
|
@@ -104,15 +95,10 @@ def as_lazy_data(data, chunks=None, asarray=False): | |
# but reduce it if larger than a default maximum size. | ||
chunks = _limited_shape(data.shape) | ||
|
||
if isinstance(data, ma.core.MaskedConstant): | ||
data = ma.masked_array(data.data, mask=data.mask) | ||
if not is_lazy_data(data): | ||
if data.shape == (): | ||
# Workaround for https://github.com/dask/dask/issues/2823. Make | ||
# sure scalar dask arrays return numpy objects. | ||
dtype = data.dtype | ||
data = _getall_delayed(data) | ||
data = da.from_delayed(data, (), dtype) | ||
else: | ||
data = da.from_array(data, chunks=chunks, asarray=asarray) | ||
data = da.from_array(data, chunks=chunks, asarray=asarray) | ||
return data | ||
|
||
|
||
|
@@ -138,7 +124,10 @@ def as_concrete_data(data): | |
# In some cases dask may return a scalar numpy.int/numpy.float object | ||
# rather than a numpy.ndarray object. | ||
# Recorded in https://github.com/dask/dask/issues/2111. | ||
dtype = data.dtype | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implication here is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the result of the compute is a |
||
data = np.asanyarray(data.compute()) | ||
if isinstance(data, ma.core.MaskedConstant): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, how is this tied up with the main point ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I reverted the code to how it was before I found that some of our tests which check that the result of realising lazy data is not a |
||
data = ma.masked_array(data.data, dtype=dtype, mask=data.mask) | ||
|
||
return data | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related, or fixing a different problem ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the way the code was before the original change. I had moved it into the
_getall
function, which I've now removed. I think it's necessary because dask doesn't likeMaskedConstant
.