Fix/multiclass prediction type safety#386
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Improves type safety around prediction loading by validating the binary/multi-class mode of stored records and refactors Classifier.set_project_settings to accept an explicit behavior argument, removing the prior requirement to set behavior_name first.
Changes:
Classifier.set_project_settingsgains optionalbehaviorarg;MultiClassClassifiermirrors the signature for parity; cross-validation now passes behavior explicitly.PredictionManager._load_prediction_recordrequires keywordexpect_multiclassand raisesValueErrorwhen the stored record's mode (presence ofclass_names) doesn't match.- New tests cover explicit-behavior precedence and cross-mode prediction rejection.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/jabs/classifier/classifier.py | Accept optional behavior arg; prefer it over self._behavior when scoping settings. |
| src/jabs/classifier/multi_class_classifier.py | Add unused behavior parameter for signature parity, with docstring. |
| src/jabs/classifier/cross_validation.py | Pass behavior explicitly to set_project_settings and reorder relative to behavior_name assignment. |
| src/jabs/project/prediction_manager.py | Add expect_multiclass keyword and raise ValueError on mode mismatch; expanded docstring. |
| tests/classifier/test_classifier.py | New tests covering explicit behavior overriding/preferring over attribute. |
| tests/classifier/test_cross_validation.py | Update fake classifier signature to match new set_project_settings. |
| tests/project/test_prediction_manager.py | New tests verifying cross-mode reads raise ValueError. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 1, 2026
keithshep
approved these changes
Jun 2, 2026
…ABS-behavior-classifier into fix/multiclass-prediction-type-safety # Conflicts: # src/jabs/classifier/multi_class_classifier.py
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.
This pull request introduces improvements to how classifier settings are scoped by behavior and adds robust validation to prediction loading to prevent mismatches between binary and multi-class prediction records. It also updates the relevant tests to ensure correct behavior in these scenarios.
Classifier settings scoping improvements:
Classifier.set_project_settingsmethod now accepts an optionalbehaviorargument, allowing explicit scoping of settings without relying on the classifier'sbehavior_nameattribute. This makes the method more flexible and avoids previous ordering requirements. (src/jabs/classifier/classifier.py[1]src/jabs/classifier/cross_validation.py[2]MultiClassClassifier.set_project_settingsmethod signature is updated for consistency, accepting a (unused)behaviorargument to match the base class, simplifying interface usage. (src/jabs/classifier/multi_class_classifier.pysrc/jabs/classifier/multi_class_classifier.pyL121-R130)behaviorarguments are preferred over the attribute and that the correct project settings are loaded. (tests/classifier/test_classifier.py[1]tests/classifier/test_cross_validation.py[2]Prediction loading validation:
ValueErroris raised instead of silently returning mis-shaped data, preventing subtle bugs. (src/jabs/project/prediction_manager.py[1] [2] [3]tests/project/test_prediction_manager.pytests/project/test_prediction_manager.pyR231-R284)