Skip to content

fix(qlib/factor loader): read factor JSON as UTF-8#1421

Open
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/factor-json-loader-utf8
Open

fix(qlib/factor loader): read factor JSON as UTF-8#1421
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/factor-json-loader-utf8

Conversation

@genisis0x

@genisis0x genisis0x commented May 29, 2026

Copy link
Copy Markdown

Description

FactorExperimentLoaderFromJsonFile and FactorTestCaseLoaderFromJsonFile (rdagent/scenarios/qlib/factor_experiment_loader/json_loader.py) opened the factor / testcase JSON files with no explicit encoding, so the read fell back to the platform default — cp1252 / gbk on 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 both open() calls so the read matches the JSON contract regardless of platform locale. No behavior change on UTF-8 locales.

Testing

json.load of a factor JSON containing non-ASCII names/descriptions now succeeds independent of locale.getpreferredencoding(). Existing ASCII factor files are unaffected.


📚 Documentation preview 📚: https://RDAgent--1421.org.readthedocs.build/en/1421/

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant