Skip to content

BUG: quantile inconsitent with median for size=0 #29315

@DerWeh

Description

@DerWeh

Describe the issue:

For empty inputs (size=0), quantile yields an Index error:

>> np.quantile([], 0.5)
IndexError: index -1 is out of bounds for axis 0 with size 0

While median yields np.float64(nan) (with warnings):

>> np.median([])
np.float64(nan)

The See also section, suggests np.quantile(..., 0.5) == np.median(...), else I find no information on the case size=0, or any mention of raised errors.
The behavior of median is consistent with mean, which follows the specification of https://data-apis.org/array-api/latest/API_specification/generated/array_api.mean.html.

I would expect quantile to return NaN for empty arrays.

Reproduce the code example:

import numpy as np
np.quantil([], 0.5)

Error message:

Python and NumPy Versions:

2.2.6
3.12.6 | packaged by conda-forge | (main, Sep 30 2024, 18:08:52) [GCC 13.3.0]

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy