Repository: dask/dask
Pull request #11489 (2024-11-04 19:48:01)

Fix quantile error in two dimensions
- [ ] Closes #xxxx
- [ ] Tests added / passed
- [ ] Passes `pre-commit run --all-files`

Found this while working on the xarray integration

github-actions[bot]: ## Unit Test Results
_See [test report](https://dask.github.io/dask/test_report.html) for an extended history of previous test failures. This is useful for diagnosing flaky tests._

     13 files  ± 0       13 suites  ±0   3h 44m 43s ⏱️ - 1m 2s
 13 288 tests + 1   12 226 ✅ +1   1 062 💤 ±0  0 ❌ ±0 
138 659 runs  +11  119 671 ✅ +9  18 988 💤 +2  0 ❌ ±0 

Results for commit a13ecd02. ± Comparison against base commit fa8fecf1.

[test-results]:data:application/gzip;base64,H4sIAEIuKWcC/03OTQrDIBCG4asE113oaNXpZYqoAWl+itFV6d2rJjVZvs/Ax3zIGCa/kcfA+G0gWw7pLJejSWFdWgtdqVzTfget//3csrUVAUCe+ArvilRCt9GEqRjt4GNc4yExL/u0lnc8uk8zlIp1PKY1tieaXaZbX5ftOs8hlSCGcW8dBY1OceaE8dzhKMBIpFA+NUp6xZQl3x9ZCgt8GgEAAA==


Patch:
diff --git a/.github/workflows/additional.yml b/.github/workflows/additional.yml
index 78bd40f9e..8e4d0467a 100644
--- a/.github/workflows/additional.yml
+++ b/.github/workflows/additional.yml
@@ -16,7 +16,7 @@ jobs:
         uses: actions/checkout@v4.1.5
 
       - name: Setup Conda Environment
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           use-mamba: true
@@ -46,7 +46,7 @@ jobs:
         uses: actions/checkout@v4.1.5
 
       - name: Setup Conda
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           use-mamba: true
diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml
index ca93fa2cc..fe2b4b8e7 100644
--- a/.github/workflows/conda.yml
+++ b/.github/workflows/conda.yml
@@ -32,7 +32,7 @@ jobs:
         with:
           fetch-depth: 0
       - name: Set up Python
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           use-mamba: true
diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml
index 07d7ebbc6..2b835b517 100644
--- a/.github/workflows/upstream.yml
+++ b/.github/workflows/upstream.yml
@@ -50,7 +50,7 @@ jobs:
         uses: actions/checkout@v4.1.5
 
       - name: Setup Conda Environment
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           use-mamba: true
diff --git a/dask/array/core.py b/dask/array/core.py
index fdf65bd24..3065406a9 100644
--- a/dask/array/core.py
+++ b/dask/array/core.py
@@ -562,7 +562,9 @@ def map_blocks(
         Dimensions lost by the function.
     new_axis : number or iterable, optional
         New dimensions created by the function. Note that these are applied
-        after ``drop_axis`` (if present).
+        after ``drop_axis`` (if present). The size of each chunk along this
+        dimension will be set to 1. Please specify ``chunks`` if the individual
+        chunks have a different size.
     enforce_ndim : bool, default False
         Whether to enforce at runtime that the dimensionality of the array
         produced by ``func`` actually matches that of the array returned by
diff --git a/dask/array/reductions.py b/dask/array/reductions.py
index a0dfb3d4f..49bbe14d8 100644
--- a/dask/array/reductions.py
+++ b/dask/array/reductions.py
@@ -1927,7 +1927,7 @@ def _span_indexers(a):
     # we have to calculate reduce(mul, list(a.shape)[:-1]) number of quantiles
     # We create an indexer combination for each of these quantiles
 
-    shapes = reduce(mul, list(a.shape)[1:-1])
+    shapes = 1 if len(a.shape) <= 2 else reduce(mul, list(a.shape)[1:-1])
     original_shapes = shapes * a.shape[0]
     indexers = [tuple(np.repeat(np.arange(a.shape[0]), shapes))]
 


Test patch:
diff --git a/.github/workflows/test-report.yaml b/.github/workflows/test-report.yaml
index 615363e6d..c84889062 100644
--- a/.github/workflows/test-report.yaml
+++ b/.github/workflows/test-report.yaml
@@ -26,7 +26,7 @@ jobs:
           repository: dask/distributed
 
       - name: Setup Conda Environment
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           condarc-file: continuous_integration/condarc
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 444a35fbb..fe76623df 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -69,7 +69,7 @@ jobs:
           java-version: "11"
 
       - name: Setup Conda Environment
-        uses: conda-incubator/setup-miniconda@v3.0.4
+        uses: conda-incubator/setup-miniconda@v3.1.0
         with:
           miniforge-version: latest
           use-mamba: true
diff --git a/dask/array/tests/test_reductions.py b/dask/array/tests/test_reductions.py
index 0c43c13fb..01625c0eb 100644
--- a/dask/array/tests/test_reductions.py
+++ b/dask/array/tests/test_reductions.py
@@ -972,3 +972,9 @@ def test_nanquantile_one_dim():
     arr = np.random.randn(10)
     darr = da.from_array(arr, chunks=(2,))
     assert_eq(da.nanquantile(darr, 0.75, axis=-1), np.nanquantile(arr, 0.75, axis=-1))
+
+
+def test_nanquantile_two_dims():
+    arr = np.random.randn(10, 10)
+    darr = da.from_array(arr, chunks=(2, -1))
+    assert_eq(da.nanquantile(darr, 0.75, axis=-1), np.nanquantile(arr, 0.75, axis=-1))