← Back to Pull requests

[python] Keep the first iteration when an sklearn iteration_range ends at 0 #12790

Closed
unknown closed this pull request without merging on Nov 04, 2026 10:51 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 17:46 UTC
Author

XGBRegressor.predict(X, iteration_range=(5, 0)) returns the prediction from every tree. Booster.predict and inplace_predict with the same range use trees 5 onward, since an end of 0 means "up to the last round" there. _get_iteration_range treats any range that ends in 0 as the default and swaps it for (0, best_iteration + 1) or (0, 0), so the first iteration gets dropped without a warning. It's the same on master and on 3.4.1. predict_proba and apply go through the same helper, and so do the dask estimators.

The fix keeps the first iteration and only fills in the end. An end of 0 still means best_iteration + 1 after early stopping, the way the early_stopping_rounds docs describe it. A first iteration past that end now hits the booster's own tree_begin <= tree_end check, the same error you'd get passing (11, 10) directly. apply with a nonzero first iteration now raises the booster's "Predict leaf supports only iteration end" error instead of quietly returning every leaf, which is the one behavior change worth calling out.

The new test sits next to test_best_iteration. It checks that (begin, 0) matches (begin, end) for predict and predict_proba, with and without early stopping, and that apply raises like the booster does. Both cases fail on master and pass with the fix, and the rest of tests/python/test_with_sklearn.py still passes.

Diff: 174 lines (+130 / -44) across 2 files Reviewer: RAMitchell Review duration: 1024m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 174 lines diff across 2 files
0.35
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.309
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12790"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.4% (MEDIUM) · Higher = larger blast radius
35.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.0% · Safe to merge
14.0%
Repository