Skip to content

BUG: prevent masked values leaking into jackknife resamples - #20582

Closed
rajpreetcodes wants to merge 1 commit into
astropy:mainfrom
rajpreetcodes:fix/jackknife-masked-array-20579
Closed

rajpreetcodes wants to merge 1 commit into
astropy:mainfrom
rajpreetcodes:fix/jackknife-masked-array-20579

Conversation

@rajpreetcodes

Copy link
Copy Markdown

Description

This pull request addresses #20579 where passing a masked array (numpy.ma.MaskedArray or astropy.utils.masked.Masked) to jackknife_resampling or jackknife_stats caused masked values to silently leak into the resampled iterations, producing incorrect estimates and standard errors.

In jackknife_resampling, allocating resamples = np.empty([n, n - 1]) as an ordinary ndarray stripped the mask upon row assignment (resamples[i] = np.delete(data, i)), which allowed invalid underlying masked values to enter subsequent calculations.

The fix compresses masked arrays to their valid unmasked observations prior to generating the jackknife resamples, matching statistical expectations for leave-one-out estimators with missing data. Regression tests covering MaskedArray resampling, statistics, and all-masked validation have been added.

Fixes #20579

AI Disclosure

N/A

  • I certify that I am human and that I take full responsibility for this pull request including all interactions with reviewers.

@giles

giles Bot commented Oct 11, 2026

Copy link
Copy Markdown

Hi 👋 and thank you for your contribution! 🙏

This pull request is being closed automatically - but don't worry, this is not the end, and we may re-open it.

For some background, we have recently started seeing a rapid increase in the number of pull requests opened. Some of these are from good-faith humans, but some of which are from autonomous LLM agents or humans using LLMs who do not have a genuine understanding of, or interest in, the project. We are therefore auto-closing pull requests from new contributors, but if you are a good-faith human, we want to make sure your pull request gets considered! So if you would like us to re-open your pull request so that it gets reviewed, you need to do two things:

  1. Add a comment here to explain why you need the changes here to be considered, as in how the bug or missing feature affects your work, or whether this is an issue you have encountered but does not affect you.

  2. Join the astropy slack using this invite link and head over to the #new-contributor-requests channel to introduce yourself and let us know about this pull request

The second step is important, as we may otherwise miss notifications about this pull request.

To be clear, our AI policy does allow the use of LLMs as part of contributions, but we need to see authentic engagement and understanding from humans making the contribution.

Notes for maintainers

If you know this is a genuine user and the PR is is compliance with the AI policy, you may re-open this straight away. After two successful merged pull requests, the user will be added to the allowlist and future PRs will no longer be closed automatically.

This user has not made any pull requests to this repository prior to this one.

In addition, here are some statistics on the user's activity on GitHub:

Last 24 hours Last 7 days
Pull requests opened 1 1
Issues opened 0 0

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@giles giles Bot closed this Oct 11, 2026
rajpreetcodes added a commit to rajpreetcodes/astropy that referenced this pull request Oct 11, 2026
@rajpreetcodes

Copy link
Copy Markdown
Author

Hi @giles, this pull request addresses #20579 where masked elements in a MaskedArray leaked into resampled jackknife slices and corrupted downstream estimates and standard errors.

I encountered this issue while running jackknife estimators on flagged astronomical time-series data. The PR includes the fix, comprehensive regression tests for MaskedArray inputs, and the towncrier changelog fragment. All test suites on CircleCI are green.

Could maintainers please reopen this PR for review?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants