Skip to content

Accept list, tuple and non-default-index Series groups in group splits - #1665

Open
Sohail Shaikh (sohailshk) wants to merge 5 commits into
microsoft:mainfrom
sohailshk:fix/group-split-groups-indexing
Open

Sohail Shaikh (sohailshk) wants to merge 5 commits into
microsoft:mainfrom
sohailshk:fix/group-split-groups-indexing

Conversation

@sohailshk

Copy link
Copy Markdown

Why are these changes needed?

groups is documented as "None or array-like", but split_type="group" indexes the labels positionally. Realistic repro (iris, train_test_split(X, y, df["cluster"]) which keeps the Series index, regression, split_type="group", eval_method="holdout"): KeyError: "None of [Index([9, 11, ...])] are in the [index]" on main; it runs on this branch (the cv variant already worked).
Other cases on main (each run): a list or tuple raises TypeError: only integer scalar arrays can be converted to a scalar index (holdout) or AttributeError: ... no attribute 'iloc' (cv, also with split_type=GroupKFold(3)). A Series whose index is a permutation of 0..n-1 raises nothing, but the holdout split stores other rows' labels in state.groups / state.groups_val (checked at state level; the effect on ranking metrics is from code reading only).
The change converts list, tuple and Series group labels (and groups_val) to an ndarray when the data is prepared. New tests: list, tuple, offset-index Series (holdout and cv), GroupKFold with a list (cv), and the permuted-index state check; 7 fail on main, all pass here. Existing test_split tests pass except two that import catboost (not installed).

Related issue number

Related: #1384/#1385, #1396/#1405, #1586 (same indexing, sample_weight side).

Checks

Checks run: black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.

AutoML.fit(split_type='group') indexed the group labels positionally with
groups[train_idx]. A list or tuple raised TypeError (holdout) or AttributeError
(cv, no .iloc), and a pd.Series with a non-default index raised KeyError in the
holdout split because it was indexed by label. Convert such group labels to an
ndarray when the data is prepared.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the group-label positional-indexing fix.

No open issues 🎉

What changed in this PR

This PR fixes positional indexing of array-like group labels in FLAML’s group-based splits, extending earlier fixes for target and sample-weight alignment.

Changes:

  • Normalize list, tuple, and pandas Series values for groups and groups_val to NumPy arrays.
  • Add regression tests for holdout and cross-validation splits, custom GroupKFold, and label alignment with permuted Series indexes.
File Description
test/​automl/​test_split.py Adds coverage for supported group containers and positional label alignment.
flaml/​automl/​task/​generic_task.py Normalizes group labels during data validation for positional indexing.

Review effort: Balanced

@thinkall Li Jiang (thinkall) 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.

Overall review of the complete patch at 1c6d739579d67873b1fa29a82e0ec29fcc09e884: the six independent Medium review-code lenses completed using gemini-4-carbon at high reasoning, with unresolved test-evidence follow-ups retained.

Please cover caller-supplied X_val/y_val/non-array groups_val, and check the labels passed to each CV fold rather than only the rows seen by RandomForestClassifier.fit. Also assert that at least one captured fit actually holds out groups: set(counts) <= {0, 10} accepts full-data fits and does not establish that on its own.

The added regression tests give 8 passed, 1 skipped on each native Python 3.10 and 3.13 stack; identical definitions on exact main give 7 failed, 1 passed, 1 skipped. This verifies the stated list/tuple/Series fixes, not a complete Spark or optional-dependency matrix. I also checked the broader pd.Index concern: it fails identically on this head and main, and is outside the explicitly stated container fix, so I am not reporting it as a new regression or requiring unrelated broadening here.

The original six reviewer outcomes and this scope adjudication are retained in local artifact-only evidence commits. No clean overall signoff or PR approval is submitted while the focused test requests remain; no foreign thread was resolved or prior review dismissed.

Posted by thinkall-agent-auto-reviewer

Spy on the labels and rows handed to each evaluated fold, cover X_val/y_val with non-array groups and groups_val, and assert that at least one fit holds groups out.
@sohailshk

Copy link
Copy Markdown
Author

Thanks for the review, thinkall. I've added the requested test coverage and pushed the changes in commit d4cf7a5b.

  1. Caller-supplied validation data
    Added tests covering caller-supplied X_val and y_val with non-array groups_val inputs, including:
  • Lists
  • Tuples
  • Pandas Series with offset indices

This ensures that validation groups are handled correctly across different input types and index configurations.
2. Per-fold group validation
Added per-fold assertions covering both the holdout and cross-validation paths.
For each fold, the tests verify that:

  • groups matches the group labels corresponding to the training rows.
  • groups_val matches the group labels corresponding to the validation rows.
  • Training and validation group sets do not overlap.

Also added an explicit assertion that at least one captured fit actually holds out groups. This ensures the tests verify genuine group separation rather than passing without exercising the intended behavior.
3. Regression verification
The new per-fold tests fail in 4 of 9 cases when generic_task.py is reverted to the version on main.
This confirms that the tests detect the behavior addressed by the existing source change rather than simply validating the expected output on the current implementation.
4. Scope of this commit
Commit d4cf7a5b contains test changes only. No source code has been modified in this commit.
5. Test results

  • Group-related tests: 21 passed.
  • Two other tests fail with ModuleNotFoundError because optional dependencies are missing in the current environment.

These dependency-related failures are unrelated to this change.
Summary
The additional coverage verifies caller-supplied validation data, non-array group inputs, and per-fold group isolation across both holdout and CV paths.
The regression checks also confirm that the new tests catch failures when the relevant source implementation is reverted to main.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the group-label normalization change.

No open issues 🎉

Review effort: Balanced

@thinkall Li Jiang (thinkall) 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.

The selected group-split regressions produce 17 passes and one existing skip on each native stack, on both current and preceding production source. The new row-alignment and nonvacuity checks improve test evidence.

Remaining test-quality follow-ups: require captured training groups to be present before comparing them; for three-fold CV, verify three nonoverlapping validation sets covering the rows rather than accepting any one held-out fold; and exercise positional indexing directly on captured caller-supplied groups_val instead of normalizing it inside the assertion.

These are assertion gaps, not newly demonstrated production row misalignment. This Low test-delta review does not supersede the retained full Medium scope or grant whole-PR approval.

Posted by thinkall-agent-auto-reviewer

@sohailshk

Copy link
Copy Markdown
Author

Implemented all three requested changes:

  • Require captured training groups to be present.
  • Verify that 3-fold CV produces three disjoint validation sets covering all rows.
  • Test positional indexing using the caller's groups_val.

The new CV test fails on main only for the list case. Both Series cases already pass because CV uses positional indexing.
Tests: test_split.py: 28 passed, 2 failed. The two failures require CatBoost and MinIO, which are not installed. Results are the same with NumPy 2.5.5 and 1.26.4.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the expanded group-label input support.

No open issues 🎉

Review effort: Balanced

@thinkall Li Jiang (thinkall) 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.

Whole-PR review at 3708aab7453614f3b6a35925f9d70d960e4b27f4: the stronger group-presence checks help, but two verified issues remain.

  • Group identity: np.asarray in flaml/automl/task/generic_task.py:265-268 turns distinct integer 1 and string "1" labels into the same string. Actual caller-supplied holdout metrics preserve those identities on main but receive only string labels on both this head and its predecessor. This is a remaining whole-PR regression, not a new production change in the latest test-only commit.
  • Assertion cardinality: the new CV helper accepts a repeated validation row because it counts sets. Appending an extra captured validation-group label also passes the current supplied-validation test, whereas the predecessor rejects it. Count the raw validation IDs and assert exact label-vector lengths.

pd.Index CV and range holdout still fail on current, predecessor and main; those are inherited array-like limitations, not newly introduced regressions. Targeted current suites passed 48 tests with 2 skips across the two native stacks. This does not establish full supported-version or optional-dependency coverage.

The Low skill verdict remains issues found. Evidence is retained locally only; no review outputs are pushed to this PR.

Posted by thinkall-agent-auto-reviewer

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants