Skip to content

da.percentile and np.percentile can have different output shapes #11989

@m-albert

Description

@m-albert

Describe the issue:

It seems that da.percentile and np.percentile return arrays of different shapes. Also confusingly da.percentile and da.nanpercentile differ in their outputs (and implementations).

Found in the context of #11988.

Minimal Complete Verifiable Example:

import dask.array as da
import numpy as np

x_np = np.ones(3)
x_da = da.from_array(x_np)

np_percentile_result = np.percentile(x_np, 50) # np.array(1.)
np_nanpercentile_result = np.nanpercentile(x_np, 50) # np.array(1.)
da_percentile_result = da.percentile(x_da, 50).compute() # np.array(1.)
da_nanpercentile_result = da.nanpercentile(x_da, 50).compute() # np.array([1.])

# ok
assert np_percentile_result.shape == np_nanpercentile_result.shape

# ok
assert np_percentile_result.shape == da_nanpercentile_result.shape

# fails
assert np_percentile_result.shape == da.percentile_result.shape

Anything else we need to know?:

Environment:

  • Dask version: 2025.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions