-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Latex variable name processing #38
Conversation
tests/test_basic.py
Outdated
assert df["Current_Jz"].attrs["long_name"] == "Current J$_z$" | ||
assert df["Particles_Px_Electron"].attrs["long_name"] == "Particles P$_x$ Electron" | ||
assert df["Particles_Py_Electron"].attrs["long_name"] == "Particles P$_y$ Electron" | ||
assert df["Particles_Pz_Electron"].attrs["long_name"] == "Particles P$_z$ Electron" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also wise to have a couple of examples where we don't want this to happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new tests for this in 14a4b65
assert _process_latex_name("Example") == "Example" | ||
assert _process_latex_name("PxTest") == "PxTest" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to check the long name for one of the variables in df
that we've not LaTeXified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to leave those as there aren't any examples of names like that but also validated against existing variables 9075383
src/sdf_xarray/__init__.py
Outdated
affix_pattern = rf"(\s+){prefix}{suffix}(\s*|$)" | ||
# Insert LaTeX format while preserving spaces | ||
replacement = rf"\1${prefix}_{suffix}$\2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can just be this?
affix_pattern = rf"(\s+){prefix}{suffix}(\s*|$)" | |
# Insert LaTeX format while preserving spaces | |
replacement = rf"\1${prefix}_{suffix}$\2" | |
affix_pattern = rf"\b{prefix}{suffix}\b" | |
# Insert LaTeX format while preserving spaces | |
replacement = rf"${prefix}_{suffix}$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it can! Ran it locally and checked tests passed
Change all
long_name
attributes to use spaces instead of underscores with Title CaseAdd LaTeX detection of variables that contain the following prefixes and suffixes:
It will convert from
Electric Field Ex
toElectric Field E$_x$
It will only convert to latex if there are spaces before and after OR if there is a space before. This is to ensure that we don't rename variables that might contain those characters within another word. e.g.
Exponential ...
Fixes #36