Repository navigation
FIX load dict bool keys as saved - #573
Open
kevincommits wants to merge 1 commit into
Open
kevincommits wants to merge 1 commit into
kevincommits wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Reference Issues/PRs
No existing issue. The new test in #570 notes this as a separate issue.
What does this implement/fix? Explain your changes.
A dict with
boolkeys does not round trip. The keys are written as the JSON keys"true"and"false", and on load each key is rebuilt asbool("false"), which isTrue:This silently drops an entry, for example from a
class_weight={False: 2, True: 1}hyperparameter. The same happens withnumpy.bool_keys and with files saved under protocols 0 to 2.The fix rebuilds a
boolornumpy.bool_key by comparing the saved string with"true", inDictNodeand in the protocol 2DictNode. Other key types are unchanged. Since only loading changes, existing files load correctly too.test_dictionary_bool_keyscoversboolandnumpy.bool_keys, and a new case intest_plain_container_v2covers protocols 0 to 2. I added a changelog entry.What I ran: the full test suite with pytest in a virtual environment (equivalent of
pixi run tests; the only errors are the CatBoost tests, which fail before this change too under a newer pytest), and the pre-commit hooks (ruff check, ruff format, pyrefly), all passing.What I did not run: the pixi environments for other scikit-learn versions.
Any other comments?
None.