Repository navigation
fix(units): stop aliasing C to degree Celsius - #672
Open
Cherith1222 wants to merge 2 commits into
Open
Cherith1222 wants to merge 2 commits into
Cherith1222 wants to merge 2 commits into
Conversation
Importing the CF unit registry currently makes C mean degree Celsius, so a thermal velocity built from electron-volts no longer converts to km/s.
UDUNITS uses C for coulomb. degC, Celsius, deg_C, and degrees_Celsius still name degree Celsius.
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.
Why
Importing the CF unit registry redefines the symbol C as degree Celsius. UDUNITS uses C for coulomb, and that redefinition makes a thermal velocity built from electron-volts fail to convert to km/s.
What changed
Scope
This covers the coulomb symbol in the example from #543. It leaves the regex preprocessor and the pint minimum alone.
Tradeoffs
Keeping C as Celsius would preserve the old alias and keep breaking coulomb. Removing it matches UDUNITS. A bare unit string C now means coulomb. The other Celsius names are unchanged.
Blast Radius
Code that quantified a value with the unit string C and meant Celsius will now get coulomb. degC and Celsius are unchanged. The in-repo what's new file points at GitHub releases for changes after February 2023, so this diff does not add a section there.
Verification
ureg("C")was degree Celsius andnp.sqrt(100 * ureg.eV / ureg.m_e).to("km/s")raised DimensionalityError.python -m pytest cf_xarray/tests/test_units.pyis 17 passed.Drafted with Cursor.