`jackknife_stats` silently gives wrong results for a `MaskedArray`: masked values leak into the resamples · Issue #20579 · astropy/astropy · GitHub
Skip to content

jackknife_stats silently gives wrong results for a MaskedArray: masked values leak into the resamples #20579

Open

Description

@ChenziqiAdam

Description

If jackknife_stats gets a numpy.ma.MaskedArray, for example a light curve with flagged bad points, it returns no error and no warning, but the estimate, bias and standard error are wrong. The full-sample statistic honours the mask. The leave-one-out resamples do not, because the masked values are copied into them as ordinary data. The result therefore depends on the value hidden under the mask.

Expected behavior

The result should match the one for the unmasked values, estimate = 2.5, bias = 0, se = 0.6455. Alternatively, jackknife_stats could raise an error saying that masked input is not supported.

How to Reproduce

import numpy as np
from astropy.stats import jackknife_stats

# 5 flux measurements; the last one is flagged bad and masked
data = np.ma.array([1.0, 2.0, 3.0, 4.0, 1000.0], mask=[0, 0, 0, 0, 1])

est, bias, se, ci = jackknife_stats(data, np.mean)
print("masked input :", est, bias, se)

est, bias, se, ci = jackknife_stats(data.compressed(), np.mean)
print("compressed   :", est, bias, se)
masked input : -795.5 798.0 199.50062656543213
compressed   : 2.5 0.0 0.6454972243679028

Versions

import astropy
astropy.system_info()
# Paste the result here

Activity

  1. rajpreetcodes commented on Oct 11, 2026

    @rajpreetcodes

    I investigated this root cause and opened PR #20582 with the fix and regression test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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