fix(qlib/factor loader): read factor JSON as UTF-8#1421
Open
genisis0x wants to merge 1 commit into
Open
Conversation
FactorExperimentLoaderFromJsonFile and FactorTestCaseLoaderFromJsonFile opened the factor/testcase JSON files without an explicit encoding, so the read used the platform default (cp1252/gbk on Windows). Factor JSON routinely carries non-ASCII content (localized factor names and descriptions), and JSON is UTF-8 by default per RFC 8259 section 8.1, so the load raised UnicodeDecodeError on non-UTF-8 locales. Pin encoding to utf-8 to match the JSON contract.
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.
Description
FactorExperimentLoaderFromJsonFileandFactorTestCaseLoaderFromJsonFile(rdagent/scenarios/qlib/factor_experiment_loader/json_loader.py) opened the factor / testcase JSON files with no explicitencoding, so the read fell back to the platform default —cp1252/gbkon Windows.Factor definition JSON routinely carries non-ASCII content (localized factor names and descriptions), and JSON is UTF-8 by default per RFC 8259 §8.1. On a non-UTF-8 locale the load therefore fails with
UnicodeDecodeError, the same class of failure already fixed for template loading.Change
Pin
encoding="utf-8"on bothopen()calls so the read matches the JSON contract regardless of platform locale. No behavior change on UTF-8 locales.Testing
json.loadof a factor JSON containing non-ASCII names/descriptions now succeeds independent oflocale.getpreferredencoding(). Existing ASCII factor files are unaffected.📚 Documentation preview 📚: https://RDAgent--1421.org.readthedocs.build/en/1421/