Repository: dask/dask
Issue category: Bug Report

Issue:
bug in dask.array.reshape_blockwise
**Minimal Complete Verifiable Example**:

```python
import dask.array

reshape_blockwise(dask.array.ones((3,)), shape=(3,), chunks=((3,),))
```
```
ValueError: Setting chunks is not allowed when reducing the number of dimensions.
```

cc @phofl 



Hints:
This is expected, we only need chunks if you increase the number of dimensions. We can calculate the chunks ourselves if we reduce the dimensions and I'd rather not validate user input.

Do you have a use-case where you need this for a case like this?
Yes, https://github.com/pydata/xarray/pull/9800/files, but I worked around it by only using `reshape_blockwise` with >=2D arrays.

xref https://github.com/pydata/xarray/issues/9425
I am a bit confused (sorry for being slow here), but the reshape_blockwise would be a no-op in the case you posted, correct? You don't expect us to do anything here?
We can definitely just return if there is nothing to do instead of validating
Yes correct. it was a no-op. AND now i'm realizing that `map_blocks` is probably a better way to do it. Feel free to close. Though I think handling the no-op would be nice.

Patch:
diff --git a/dask/array/reshape.py b/dask/array/reshape.py
index 1cc79090a64..b824110c7d5 100644
--- a/dask/array/reshape.py
+++ b/dask/array/reshape.py
@@ -473,6 +473,9 @@ def reshape_blockwise(
 
     _sanity_checks(x, shape)
 
+    if len(shape) == x.ndim and shape == x.shape:
+        return Array(x.dask, x.name, x.chunks, meta=x)
+
     outname = "reshape-blockwise-" + tokenize(x, shape)
     chunk_tuples = list(product(*(range(len(c)) for i, c in enumerate(x.chunks))))
 
@@ -515,9 +518,6 @@ def reshape_blockwise(
         x.shape, shape, x.chunks, disallow_dimension_expansion=True
     )
 
-    if len(shape) == x.ndim:
-        return Array(x.dask, x.name, x.chunks, meta=x)
-
     # Convert input chunks to output chunks
     out_shapes = [
         _convert_to_shape(c, mapper_in, one_dimensions)


Test patch:
diff --git a/dask/array/tests/test_reshape.py b/dask/array/tests/test_reshape.py
index 14fb84ba919..1473d97d120 100644
--- a/dask/array/tests/test_reshape.py
+++ b/dask/array/tests/test_reshape.py
@@ -411,12 +411,11 @@ def test_reshape_blockwise_raises_for_expansion():
         reshape_blockwise(arr, (3, 2, 9))
 
 
-@pytest.mark.parametrize("shape", [(18, 3), (6, 3, 3)])
-def test_reshape_blockwise_dimension_reduction_and_chunks(shape):
+def test_reshape_blockwise_dimension_reduction_and_chunks():
     x = np.arange(0, 54).reshape(6, 3, 3)
     arr = from_array(x, chunks=(3, 2, (2, 1)))
     with pytest.raises(ValueError, match="Setting chunks is not allowed when"):
-        reshape_blockwise(arr, shape, arr.chunks)
+        reshape_blockwise(arr, (18, 3), arr.chunks)
 
 
 def test_reshape_blockwise_identity():
@@ -426,6 +425,10 @@ def test_reshape_blockwise_identity():
     assert len(arr.dask) == len(result.dask)
     assert_eq(result, x)
 
+    result = reshape_blockwise(arr, (6, 3, 3), chunks=arr.chunks)
+    assert len(arr.dask) == len(result.dask)
+    assert_eq(result, x)
+
 
 def test_argwhere_reshaping_not_concating_chunks():
     # GH#10080