Fix unescaped backslash in theta label in model_variables.json - #1193
Open
arihantlodha-cmd wants to merge 1 commit into
Open
Fix unescaped backslash in theta label in model_variables.json#1193arihantlodha-cmd wants to merge 1 commit into
arihantlodha-cmd wants to merge 1 commit into
Conversation
Closes PSLmodels#1015. The 'theta' label in model_variables.json used a single backslash ($\theta_j$), which JSON parses into a tab character, so the label failed to render properly in plots. Escape it ($\\theta_j$) to match the already-corrected \\tilde labels. Adds test_constants.py guarding against control characters in any VAR_LABELS/ToGDP_LABELS entry.
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.
Closes #1015.
The
thetalabel inmodel_variables.jsonwas written with a single backslash:JSON interprets
\tas a tab character, so\thetaparsed to<TAB>hetaand the label failed to render as LaTeX in plots. This escapes the backslash so it parses to a literal\theta:This matches the convention already used by the other LaTeX labels in the file — the
\\tildelabels forcandp_tildewere already written with escaped backslashes and render correctly. I went with escaping the JSON source (rather than casting to raw strings at read time, as the issue floated) because it's consistent with those existing labels and doesn't require any change to howconstants.pyloads the file.thetawas the only remaining label with an unescaped backslash.Also adds
tests/test_constants.py::test_labels_have_no_control_characters, which asserts that noVAR_LABELS/ToGDP_LABELSentry contains a control character — guarding against this class of bug being reintroduced.Testing
pytest tests/test_constants.pypasses; confirmed the test fails on the pre-fix JSON.VAR_LABELS["theta"] == "Replacement rate ($\\theta_j$)"(literal backslash, no tab) and no other labels contain control characters.ruff format --check .,ruff check ., andlinecheckclean.