Changelog¶
v0.2.1¶
Added
THIRD_PARTY_LICENSES.mdandsrc/pint_cf/resources/registry/UDUNITS2-COPYRIGHT.txt: the unit database this package is built on is redistributed from UDUNITS-2, whose license requires its copyright notice to be reproduced - needed for the conda-forge submission checklist (“package does not vendor other packages… without their license”). Every generated registry file now also points to it in its own header commentFixed
tools/xmlrd.py(the UDUNITS-2 XML → pint registry generator): it broke aftercf_string_to_pintstarted rejecting numeric-offset units (e.g.K @ 273.15) outright, since the generator relies on that exact string (pint’s"unit; offset: value"syntax) to definedegree_Celsius/degree_Fahrenheitfrom UDUNITS-2’s own XML - valid there (a registry definition), unlike as a runtime unit expression. Added_unit_definition_from_udunits, a private function used only bytools/xmlrd.pyfor this -cf_string_to_pintitself is unchanged, so this doesn’t reopen the footgun for any other caller
v0.2.0¶
Added CF units not supported by UDUNITS-2 (#10), on by default in
cf_unitregistry()(passcf_extensions=Falseto get a plain UDUNITS-2-only registry instead), sourced fromcfunits(github.com/NCAS-CMS/cfunits), the CF ecosystem’s reference implementation for these additions:level,sigma_level,layer: dimensionless vertical-coordinate placeholders kept only for COARDS backwards compatibility - parsing one raisesDeprecationWarning, since CF itself calls this use deprecated outrightpractical_salinity_unit/psu=1e-3(not1, as CF’s own FAQ suggests)decibel/dB,bel: plain dimensionless ratio units, matchingcfunits/cf-units- the physical reference level adBvalue is relative to depends on the variable’sstandard_name, which is out of scope for a unit-string converterReassigned the
Svsymbol fromsieverttosverdrup, matching CF/cfunitsinstead of UDUNITS-2’s own SI-based choice; also fixedrem(defined upstream ascSv) so it keeps meaning centisievert instead of being silently corrupted into a fraction of a sverdrup by the reassignment
Added
CFContext, a context manager for CF’sunits_metadataattribute (CF-1.11, #9): forces a bare temperature unit to itsdelta_counterpart under"temperature: difference", honored transparently by native pint calls (ureg.Quantity(...),ureg(...)) - no pint-cf-specific replacement needed."temperature: unknown"/absent needs no special handling, since pint’s own defaultas_delta=Truealready applies UDUNITS’ compound-expression heuristic."temperature: on_scale"on a compound expression raisesValueError, since it can’t be honored through the preprocessor pipeline (useureg.Quantity(value, units, as_delta=False)directly for that rare case)Added
cf_attributes_for(unit_or_quantity), the reverse ofCFContext: derives CF variable attributes (currently justunits_metadata) from an already-computed Unit/Quantity as a dict, ready to merge into a NetCDF variable’s attributes. Returns{}for a non-temperature unit, and{"units_metadata": "temperature: unknown"}for Kelvin/Rankine, which have no offset and therefore nodelta_counterpart - on_scale and difference are numerically identical for them and cannot be recovered from the unit aloneFixed two
CFContext/"temperature: difference"edge cases found during a follow-up test review: an explicit unity power (e.g.degree_C**1) was silently treated as on_scale instead of honoring the explicit metadata; a parenthesized bare unit (e.g.(degree_C)) produced the invaliddelta_(degree_C)instead ofdelta_degree_Celsius. Also made the delta_ prefixing idempotent, since pint can re-run the preprocessor on an already-prefixed string within the same contextFixed a shift-by-number unit (e.g.
K @ 273.15,a from 1) always crashing downstream with a confusing, unrelated pint error (Unit expression cannot have a scaling factor.): the transform previously produced pint’s"unit; offset: value"syntax, which is only valid when defining a new named unit, not as a runtime unit expression -cf_string_to_pintnow raisesNotImplementedErrorexplicitly instead, with a pointer toureg.define(...)as the manual workaroundFixed the UDUNITS-2 grammar (
udunits2.lark) to match the original UDUNITS-2 parser:per/PERdivision keyword is now properly case-insensitive (e.g."Per"now works too)Malformed superscript exponents (e.g.
m²⁻) are now rejected instead of silently producing an invalid pint stringreis now required in logarithmic units (lg(re ...)), matching UDUNITS-2’s own grammar
Simplified timestamp parsing: removed grammar rules/transformer methods whose result was never used, since a shift by timestamp always raises
NotImplementedError(pint has no time-origin concept)Removed a dead
division_fmtinCFFormatter’s long form (it never had any effect on the output)Fixed an inverted condition in
tools/xmlrd.py’s unused_get_delta_aliashelper and removed the duplicate inline logic it replacesHardened
tools/xmlrd.pyagainst a fragile<noplural/>assumption in the UDUNITS-2 XMLResynced
tools/xml/*.xmlwith upstream UDUNITS-2 (fixesfootcandle’s conversion factor)
v0.1.1 (2026-04-08)¶
Initial release