Repository: dask/dask

Issue:
Indexing 0-D dask array handling raises exceptions
**What happened**:
The following code raises an exception:
```
>>> import numpy
>>> import dask.array
>>> dask.array.from_array(numpy.zeros((3, 0)))[[0]]
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
    ...
OverflowError: cannot convert float infinity to integer
```

**What you expected to happen**:
I would expect this to match numpy behavior:
```python
>>> import numpy
>>> numpy.zeros((3, 0))[[0]]
array([], shape=(1, 0), dtype=float64)
```

**Minimal Complete Verifiable Example**:

```
>>> import numpy
>>> import dask.array
>>> dask.array.from_array(numpy.zeros((3, 0)))[[0]]
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
    ...
OverflowError: cannot convert float infinity to integer
```

**Anything else we need to know?**: nope

**Environment**: linux

- Dask version: 2022.01.0
- Python version: 3.9
- Operating System: linux
- Install method (conda, pip, source): pip


Discussion:
Thanks for including the minimal reproducer! It looks like the raise is coming from a divide by zero in the array slicing logic, I'll dig a bit more.

Full traceback for reference

```ipython
In [19]: x = da.from_array(np.zeros((3, 0)))

In [20]: x[[0]]
/Users/ddavis/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/slicing.py:647: RuntimeWarning: divide by zero encountered in long_scalars
  maxsize = math.ceil(nbytes / (other_numel * itemsize))
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Input In [20], in <module>
----> 1 x[[0]]

File ~/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/core.py:1847, in Array.__getitem__(self, index)
   1844     return self
   1846 out = "getitem-" + tokenize(self, index2)
-> 1847 dsk, chunks = slice_array(out, self.name, self.chunks, index2, self.itemsize)
   1849 graph = HighLevelGraph.from_collections(out, dsk, dependencies=[self])
   1851 meta = meta_from_array(self._meta, ndim=len(chunks))

File ~/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/slicing.py:174, in slice_array(out_name, in_name, blockdims, index, itemsize)
    171 index += (slice(None, None, None),) * missing
    173 # Pass down to next function
--> 174 dsk_out, bd_out = slice_with_newaxes(out_name, in_name, blockdims, index, itemsize)
    176 bd_out = tuple(map(tuple, bd_out))
    177 return dsk_out, bd_out

File ~/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/slicing.py:196, in slice_with_newaxes(out_name, in_name, blockdims, index, itemsize)
    193         where_none[i] -= n
    195 # Pass down and do work
--> 196 dsk, blockdims2 = slice_wrap_lists(out_name, in_name, blockdims, index2, itemsize)
    198 if where_none:
    199     expand = expander(where_none)

File ~/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/slicing.py:262, in slice_wrap_lists(out_name, in_name, blockdims, index, itemsize)
    260 if all(is_arraylike(i) or i == slice(None, None, None) for i in index):
    261     axis = where_list[0]
--> 262     blockdims2, dsk3 = take(
    263         out_name, in_name, blockdims, index[where_list[0]], itemsize, axis=axis
    264     )
    265 # Mixed case. Both slices/integers and lists. slice/integer then take
    266 else:
    267     # Do first pass without lists
    268     tmp = "slice-" + tokenize((out_name, in_name, blockdims, index))

File ~/.pyenv/versions/3.10.2/envs/dask-awkward/lib/python3.10/site-packages/dask/array/slicing.py:647, in take(outname, inname, chunks, index, itemsize, axis)
    645     warnsize = maxsize = math.inf
    646 else:
--> 647     maxsize = math.ceil(nbytes / (other_numel * itemsize))
    648     warnsize = maxsize * 5
    650 split = config.get("array.slicing.split-large-chunks", None)

OverflowError: cannot convert float infinity to integer
```
@douglasdavis if this is a regression, just wanted to make sure you are aware that there were recent changes in https://github.com/dask/dask/pull/8538
Doesn't appear to be a regression: it has existed since at least 2021.11.2

Resolving patch:
diff --git a/dask/array/slicing.py b/dask/array/slicing.py
--- a/dask/array/slicing.py
+++ b/dask/array/slicing.py
@@ -641,7 +641,7 @@ def take(outname, inname, chunks, index, itemsize, axis=0):
     other_chunks = [chunks[i] for i in range(len(chunks)) if i != axis]
     other_numel = np.prod([sum(x) for x in other_chunks])
 
-    if math.isnan(other_numel):
+    if math.isnan(other_numel) or other_numel == 0:
         warnsize = maxsize = math.inf
     else:
         maxsize = math.ceil(nbytes / (other_numel * itemsize))


Test patch:
diff --git a/dask/array/tests/test_slicing.py b/dask/array/tests/test_slicing.py
--- a/dask/array/tests/test_slicing.py
+++ b/dask/array/tests/test_slicing.py
@@ -1065,3 +1065,9 @@ def test_slice_array_3d_with_bool_numpy_array():
     actual = array[mask].compute()
     expected = np.arange(13, 24)
     assert_eq(actual, expected)
+
+
+def test_slice_array_null_dimension():
+    array = da.from_array(np.zeros((3, 0)))
+    expected = np.zeros((3, 0))[[0]]
+    assert_eq(array[[0]], expected)