Repository navigation
Conversation
Give a zero weight to the NaNs and use the weighted quantile, instead of a separate code path that failed to broadcast 1-D weights (numpygh-29709). A slice left with only NaNs or zero weights gives NaN and a RuntimeWarning. Refresh of numpygh-30066 on the current main. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refresh of numpy#30066 on the current main (squashed, conflicts with the
weak_qand NaT changes resolved). Staged here until there is room under the open PR limit upstream.Fixes numpy#29709 and, for the weighted case, part of numpy#16575.
What it does
Weighted
nanquantile/nanpercentileno longer has its own code path: the NaNs get a zero weight and the weighted quantile does the rest, as in scikit-learn andscipy.stats. This fixes theIndexErrorwith 1-D weights.A slice left with only NaNs or zero weights returns NaN with a
RuntimeWarning, for the three cases discussed with seberg in numpy#30066:[1, 2][0, 0]ValueError(invalid weights)[1, nan][0, 1]ValueError(invalid weights)[nan, nan][1, 1]The warning is "Slice encountered with all NaN or 0-weight samples" in the three cases.
Changes compared to numpy#30066
np.isnandoes not support them), and datetime/timedelta arrays get NaT for an empty sliceTo decide before going upstream
np.quantilestill raises for all-zero weights, sonanquantileandquantilenow differ on input without NaNs._remove_nan_1dkeeps its now unusedsecond_arr1dargument.Checks
numpy/libandnumpy/matests pass (9501 passed). On 400 random weighted calls (float, int and timedelta, 1 to 3 dims), results are the same as main except for the slices of the table above.🤖 Generated with Claude Code