Repository navigation
Never drop or shadow feature_dict groups with auto-filled columns (#81) - #85
Merged
Merged
Conversation
Fixes #81. _feature_dict_to_features stored user groups and auto-filled singleton columns in one dict keyed by logical name, so an int key equal to the index of a column no group lists was overwritten by that column's singleton (configure_feature_dict(2, {0: [1]}) -> [[0]]), silently dropping the group from training. Now raise a ValueError naming the clashing keys. str keys and non-colliding int keys are unchanged. Existing tests missed it because every int-key case listed the key's own column, and several regression tests compare against configure_feature_dict itself. Added collision tests (configure and fit) and an every-column-exactly-once invariant test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Auto-filled column i is named str(i) unless a feature_dict key already
uses that name, in which case it becomes "<i>_1" ("<i>_2", ...). This
replaces the ValueError from the previous commit: {0: [2, 3]} now keeps
the user's group "0" and names column 0 "0_1". It also fixes the
duplicate-name case for str keys ({"0": [1, 2]} gave ("0", "0")). Keys
whose string forms coincide (0 and "0") now raise ValueError.
Three blind regression tests asserted the old raise/duplicate behaviour;
updated per the maintainer's decision on the new naming rule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # .test-checker/ledger.jsonl # sgtlearn/_features.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.
Fixes #81.
Root cause
_feature_dict_to_featuresstored user groups and auto-filled singleton columns in one dict keyed by logical name. Anintkey equal to the index of a column no group lists was overwritten by that column's auto-filled singleton, so the group was silently dropped from training:A
strkey like"0"didn't lose data but produced duplicate logical names (("0", "0")), makingexport_text/plot_treelabels ambiguous.Fix
Auto-filled column
iis namedstr(i)unless a user key already has that name; then it becomes"<i>_1"(_2, … until free). User keys always keep their names.Keys whose string forms coincide (
{0: …, "0": …}) now raiseValueError, since their names would be ambiguous. Ordering is unchanged (int keys and auto-filled columns first, then str keys, each by name). Docstrings forconfigure_feature_dictandProcessedFeatures.logical_namesupdated.(The first commit raised
ValueErroron collision; the follow-up commit replaces that with renaming.)Why no test caught it
int-key test happened to list the key's own column ({0: [0, 1, 2]},{i: [i]}, …), so the collision never occurred.configure_feature_dictitself, so they share the bug.Tests
tests/test_features.py: rename cases (int key, str key, suffix already taken), same-string-form keys raise,fitkeeps the group, and every-column-exactly-once + unique-names invariant across int/str/mixed keys.tests/regression/test_sgtlearn_features_py__feature_dict_to_features_1.py: 23 blind tests from test-checker runr-20261002-215910-e7c6(0 misguided). Three that encoded the interim raise / duplicate-name behaviour were updated to the renaming rule.Not in this PR
intkeys still sort as strings (10before9), as documented; changing it would reorderfeature_importances_.categorical-features.ipynbcell 3 and theProcessedFeaturesdocstring are also edited on the Update Stale Docs and Tutorials #77 docs branch; expect a small docstring conflict there.🤖 Generated with Claude Code