Skip to content

[python-package] Enable ruff rule B905 - #7278

Merged
borchero merged 5 commits into
masterfrom
b905
May 16, 2026
Merged

borchero merged 5 commits into
masterfrom
b905

Conversation

@borchero

Copy link
Copy Markdown
Member

Motivation

Follow-up to #7276, see #7276 (comment).

Comment on lines +574 to +576
test_id = np.array_split(randidx, nfold)
train_id = [np.concatenate([test_id[i] for i in range(nfold) if k != i]) for k in range(nfold)]
folds = zip(train_id, test_id)
folds = zip(train_id, test_id, strict=True)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While, in all other places, this PR just adds strict=True, this uncovered an actual bug where we'd drop data if num_data is not divisible by nfold

cv_res = lgb.cv(params, lgb_train, num_boost_round=20, nfold=3, stratified=False, return_cvbooster=True)
cv_booster = cv_res["cvbooster"].boosters
cv_mse_errors = [mean_squared_error(y, cb.predict(X)) < 463 for cb in cv_booster]
cv_mse_errors = [mean_squared_error(y, cb.predict(X)) < 504 for cb in cv_booster]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to change as a result of the fix

@mayer79 mayer79 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, LGTM

@borchero
borchero enabled auto-merge (squash) May 16, 2026 10:41
@borchero
borchero merged commit 634c864 into master May 16, 2026
75 of 77 checks passed
@borchero
borchero deleted the b905 branch May 16, 2026 10:57
@jameslamb

Copy link
Copy Markdown
Member

Hey cool that this uncovered a real bug! Thanks for this.

I changed the label to fix so it'll be categorized that way in the release notes. Please do remember to remove awaiting review before merging.

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.

3 participants