Skip to content

BUG/DOC: numpy.ma.median return dtype does not match documented behavior #31486

@GeraldineGalindo

Description

@GeraldineGalindo

Describe the issue:

According to the documentation for ma.median: Return data-type is float64 for integers and floats smaller than float64, or the input data-type, otherwise.

However, in the following example, an input array with dtype float16 produces a result with dtype float16 rather than float64.

I have observed a similar mismatch with the documentation in: numpy.nanpercentile, numpy.nanquantile, and numpy.quantile. I would be happy to provide minimal reproducing examples for them as well if helpful.

Could this be an outdate on the documentation?

Related to: #29003

Reproduce the code example:

import numpy as np
import numpy.ma as ma

arr = np.array([0, 1, 2, 3], dtype=np.float16)
m = ma.median(arr)

print("value:", m)
print("dtype:", np.asarray(m).dtype)

Error message:

dtype: float16 --> This result does not appear to match the documented return dtype behavior.

Python and NumPy Versions:

2.4.3
3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0]

Runtime Environment:

No response

How does this issue affect you or how did you find it:

This issue was identified by an automated testing tool currently being developed by our research team.
Before reporting it, we reviewed the code, documentation and checked the latest development version of Numpy to confirm it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions