Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: quantile should error when weights are all zeros #28589

Copy link
Copy link
@lucyleeow

Description

@lucyleeow
Issue body actions

Describe the issue:

np.quantile with weights being all zeros should probably give a error/warning. It's effectively like asking for a quantile of an empty array. Currently numpy seems to return the first sample.

Reproduce the code example:

np.quantile([1,2,3,4], 0.5, weights=[0,0,0,0], method='inverted_cdf')

Error message:

/.../numpy/lib/_function_base_impl.py:4858: RuntimeWarning: invalid value encountered in divide
  cdf /= cdf[-1, ...]  # normalization to 1
Out[9]: array(1)

Python and NumPy Versions:

2.1.3
3.13.0 | packaged by conda-forge | (main, Nov 27 2024, 19:18:50) [GCC 13.3.0]

Runtime Environment:

No response

Context for the issue:

Context: Noticed when looking into scikit-learn/scikit-learn#31032

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.