Repository: dask/dask

Issue:
Is Masked-array arithmetic getting masks wrong ?
Arithmetic operations between a dask array and a numpy array have the effect of ignoring any mask on the latter.

Like this :
```
>>> lazy = da.asarray([5, 6])
>>> mask = np.ma.masked_array([2, 3], mask=[0, 1])
>>> (lazy + mask).compute()
array([7, 9])
>>> 
>>> # But expected ...
... lazy.compute() + mask
masked_array(data=[7, --],
             mask=[False,  True],
       fill_value=999999)
>>> 
```

However, if we *explicitly* wrap the masked array as a dask array, all is well ...
```
>>> (lazy + da.asanyarray(mask)).compute()
masked_array(data=[1, --],
             mask=[False,  True],
       fill_value=999999)
>>> 
```

(BUT: only using `da.asanyarray` : `da.asarray` does not work)


Discussion:

Patch:
diff --git a/dask/array/core.py b/dask/array/core.py
index 61158f7c5..08ca79f7e 100644
--- a/dask/array/core.py
+++ b/dask/array/core.py
@@ -2428,7 +2428,7 @@ def unify_chunks(*args, **kwargs):
     if not args:
         return {}, []
 
-    arginds = [(asarray(a) if ind is not None else a, ind)
+    arginds = [(asanyarray(a) if ind is not None else a, ind)
                for a, ind in partition(2, args)]  # [x, ij, y, jk]
     args = list(concat(arginds))  # [(x, ij), (y, jk)]
     warn = kwargs.get('warn', True)
@@ -2934,19 +2934,12 @@ def asarray(a, **kwargs):
     >>> da.asarray(y)
     dask.array<array, shape=(2, 3), dtype=int64, chunksize=(2, 3)>
     """
-    def frame_types():
-        try:
-            import dask.dataframe as dd
-            return (dd.Series, dd.DataFrame)
-        except ImportError:
-            return ()
-
     if isinstance(a, Array):
         return a
-    if isinstance(a, (list, tuple)) and any(isinstance(i, Array) for i in a):
-        a = stack(a)
-    elif isinstance(a, frame_types()):
+    elif hasattr(a, 'to_dask_array'):
         return a.to_dask_array()
+    elif isinstance(a, (list, tuple)) and any(isinstance(i, Array) for i in a):
+        a = stack(a)
     elif not isinstance(getattr(a, 'shape', None), Iterable):
         a = np.asarray(a)
     return from_array(a, chunks=a.shape, getitem=getter_inline, **kwargs)
diff --git a/docs/source/develop.rst b/docs/source/develop.rst
index 3e0ad25f7..d22755cb1 100644
--- a/docs/source/develop.rst
+++ b/docs/source/develop.rst
@@ -88,7 +88,7 @@ environment on your computer to compile them when installing with ``pip``::
 Install Dask and dependencies::
 
    cd dask
-   pip install -e .[complete]
+   pip install -e ".[complete]"
 
 For development, Dask uses the following additional dependencies::
 


Test patch:
diff --git a/dask/array/tests/test_masked.py b/dask/array/tests/test_masked.py
index 6608d2cc4..222e46c5c 100644
--- a/dask/array/tests/test_masked.py
+++ b/dask/array/tests/test_masked.py
@@ -348,3 +348,17 @@ def test_average_weights_with_masked_array():
     da_avg = da.ma.average(d_a, weights=d_weights, axis=1)
 
     assert_eq(np_avg, da_avg)
+
+
+def test_arithmetic_results_in_masked():
+    mask = np.array([[True, False],
+                     [True, True],
+                     [False, True]])
+    x = np.arange(6).reshape((3, 2))
+    masked = np.ma.array(x, mask=mask)
+    dx = da.from_array(x, chunks=(2, 2))
+
+    res = dx + masked
+    sol = x + masked
+    assert_eq(res, sol)
+    assert isinstance(res.compute(), np.ma.masked_array)