Repository: pydata/sparse

Issue:
Bug in converting from DOK to COO
I originally noticed this bug when I tried the following, 

`sparse.DOK.from_coo(sparse.ones((2,2), dtype=bool)).to_coo().todense()`.

It yields 

```
array([[0., 0.],
       [0., 0.]])
```

However, the issue is even more basic for example the following:

`sparse.DOK.from_coo(sparse.ones((2,2))).to_coo().todense()`,

yields the same result,

```
array([[0., 0.],
       [0., 0.]])
```

The correct results ought to be 

```
array([[True, True],
       [True, True]])
```

and 

```
array([[1., 1.],
       [1., 1.]])
```

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=h1) Report
> Merging [#226](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=desc) into [master](https://codecov.io/gh/pydata/sparse/commit/b7381b4298878ae1642d679e4b129cadb43302f4?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pydata/sparse/pull/226/graphs/tree.svg?width=650&token=H212u0Uxxw&height=150&src=pr)](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #226   +/-   ##
=======================================
  Coverage   97.61%   97.61%           
=======================================
  Files          11       11           
  Lines        1549     1549           
=======================================
  Hits         1512     1512           
  Misses         37       37
```


| [Impacted Files](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sparse/coo/core.py](https://codecov.io/gh/pydata/sparse/pull/226/diff?src=pr&el=tree#diff-c3BhcnNlL2Nvby9jb3JlLnB5) | `96.71% <100%> (ø)` | :arrow_up: |
| [sparse/dok.py](https://codecov.io/gh/pydata/sparse/pull/226/diff?src=pr&el=tree#diff-c3BhcnNlL2Rvay5weQ==) | `95.57% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=footer). Last update [b7381b4...1bf2e3a](https://codecov.io/gh/pydata/sparse/pull/226?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/sparse/coo/core.py b/sparse/coo/core.py
index 71fe0d5..727df16 100644
--- a/sparse/coo/core.py
+++ b/sparse/coo/core.py
@@ -479,11 +479,9 @@ class COO(SparseArray, NDArrayOperatorsMixin):
             ndim = 0 if shape is None else len(shape)
             coords = np.empty((ndim, 0), dtype=np.uint8)
             data = np.empty((0,))
+            shape = () if shape is None else shape
 
-            return COO(coords, data, shape=() if shape is None else shape,
-                       sorted=True, has_duplicates=False)
-
-        if not isinstance(x[0][0], Iterable):
+        elif not isinstance(x[0][0], Iterable):
             coords = np.stack(x[1], axis=0)
             data = np.asarray(x[0])
         else:
diff --git a/sparse/dok.py b/sparse/dok.py
index b4f1233..1351cbd 100644
--- a/sparse/dok.py
+++ b/sparse/dok.py
@@ -125,7 +125,7 @@ class DOK(SparseArray):
     def _make_shallow_copy_of(self, other):
         self.dtype = other.dtype
         self.data = other.data
-        super(DOK, self).__init__(other.shape)
+        super(DOK, self).__init__(other.shape, fill_value=other.fill_value)
 
     @classmethod
     def from_coo(cls, x):


Test patch:
diff --git a/sparse/tests/test_dok.py b/sparse/tests/test_dok.py
index 2443f33..e9d3d4a 100644
--- a/sparse/tests/test_dok.py
+++ b/sparse/tests/test_dok.py
@@ -169,3 +169,11 @@ def test_asformat(format):
     s2 = s.asformat(format)
 
     assert_eq(s, s2)
+
+
+def test_coo_fv_interface():
+    s1 = sparse.full((5, 5), fill_value=1+np.random.rand())
+    s2 = sparse.DOK(s1)
+    assert_eq(s1, s2)
+    s3 = sparse.COO(s2)
+    assert_eq(s1, s3)