ucon 2.2.0__tar.gz → 2.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. {ucon-2.2.0 → ucon-2.2.1}/.github/workflows/publish.yaml +27 -0
  2. {ucon-2.2.0 → ucon-2.2.1}/CHANGELOG.md +61 -0
  3. {ucon-2.2.0/ucon.egg-info → ucon-2.2.1}/PKG-INFO +1 -1
  4. {ucon-2.2.0 → ucon-2.2.1}/ucon/core/_types.py +88 -6
  5. {ucon-2.2.0 → ucon-2.2.1/ucon.egg-info}/PKG-INFO +1 -1
  6. {ucon-2.2.0 → ucon-2.2.1}/ucon.egg-info/scm_file_list.json +1 -0
  7. ucon-2.2.1/ucon.egg-info/scm_version.json +8 -0
  8. ucon-2.2.0/ucon.egg-info/scm_version.json +0 -8
  9. {ucon-2.2.0 → ucon-2.2.1}/.github/workflows/downstream.yaml +0 -0
  10. {ucon-2.2.0 → ucon-2.2.1}/.github/workflows/tests.yaml +0 -0
  11. {ucon-2.2.0 → ucon-2.2.1}/.gitignore +0 -0
  12. {ucon-2.2.0 → ucon-2.2.1}/.gitmodules +0 -0
  13. {ucon-2.2.0 → ucon-2.2.1}/LICENSE +0 -0
  14. {ucon-2.2.0 → ucon-2.2.1}/MANIFEST.in +0 -0
  15. {ucon-2.2.0 → ucon-2.2.1}/Makefile +0 -0
  16. {ucon-2.2.0 → ucon-2.2.1}/NOTICE +0 -0
  17. {ucon-2.2.0 → ucon-2.2.1}/README.md +0 -0
  18. {ucon-2.2.0 → ucon-2.2.1}/ROADMAP.md +0 -0
  19. {ucon-2.2.0 → ucon-2.2.1}/SECURITY.md +0 -0
  20. {ucon-2.2.0 → ucon-2.2.1}/SUPPORT.md +0 -0
  21. {ucon-2.2.0 → ucon-2.2.1}/mkdocs.yml +0 -0
  22. {ucon-2.2.0 → ucon-2.2.1}/netlify.toml +0 -0
  23. {ucon-2.2.0 → ucon-2.2.1}/pyproject.toml +0 -0
  24. {ucon-2.2.0 → ucon-2.2.1}/requirements.txt +0 -0
  25. {ucon-2.2.0 → ucon-2.2.1}/setup.cfg +0 -0
  26. {ucon-2.2.0 → ucon-2.2.1}/ucon/__init__.py +0 -0
  27. {ucon-2.2.0 → ucon-2.2.1}/ucon/_active.py +0 -0
  28. {ucon-2.2.0 → ucon-2.2.1}/ucon/_algebra_cache.py +0 -0
  29. {ucon-2.2.0 → ucon-2.2.1}/ucon/_bootstrap.py +0 -0
  30. {ucon-2.2.0 → ucon-2.2.1}/ucon/_cache.py +0 -0
  31. {ucon-2.2.0 → ucon-2.2.1}/ucon/aspects/__init__.py +0 -0
  32. {ucon-2.2.0 → ucon-2.2.1}/ucon/aspects/exceptions.py +0 -0
  33. {ucon-2.2.0 → ucon-2.2.1}/ucon/aspects/forest.py +0 -0
  34. {ucon-2.2.0 → ucon-2.2.1}/ucon/aspects/resolution.py +0 -0
  35. {ucon-2.2.0 → ucon-2.2.1}/ucon/aspects/types.py +0 -0
  36. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/__init__.py +0 -0
  37. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/builtin.py +0 -0
  38. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/graph.py +0 -0
  39. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/ops.py +0 -0
  40. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/transforms.py +0 -0
  41. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/types.py +0 -0
  42. {ucon-2.2.0 → ucon-2.2.1}/ucon/basis/vector.py +0 -0
  43. {ucon-2.2.0 → ucon-2.2.1}/ucon/checking.py +0 -0
  44. {ucon-2.2.0 → ucon-2.2.1}/ucon/comprehensive.ucon.toml +0 -0
  45. {ucon-2.2.0 → ucon-2.2.1}/ucon/constants.py +0 -0
  46. {ucon-2.2.0 → ucon-2.2.1}/ucon/constants.pyi +0 -0
  47. {ucon-2.2.0 → ucon-2.2.1}/ucon/contexts.py +0 -0
  48. {ucon-2.2.0 → ucon-2.2.1}/ucon/conversion.py +0 -0
  49. {ucon-2.2.0 → ucon-2.2.1}/ucon/core/__init__.py +0 -0
  50. {ucon-2.2.0 → ucon-2.2.1}/ucon/core/_parsing_graph.py +0 -0
  51. {ucon-2.2.0 → ucon-2.2.1}/ucon/core/exceptions.py +0 -0
  52. {ucon-2.2.0 → ucon-2.2.1}/ucon/dimension.py +0 -0
  53. {ucon-2.2.0 → ucon-2.2.1}/ucon/dimension.pyi +0 -0
  54. {ucon-2.2.0 → ucon-2.2.1}/ucon/expressions.py +0 -0
  55. {ucon-2.2.0 → ucon-2.2.1}/ucon/formulas/__init__.py +0 -0
  56. {ucon-2.2.0 → ucon-2.2.1}/ucon/formulas/exceptions.py +0 -0
  57. {ucon-2.2.0 → ucon-2.2.1}/ucon/formulas/registry.py +0 -0
  58. {ucon-2.2.0 → ucon-2.2.1}/ucon/formulas/types.py +0 -0
  59. {ucon-2.2.0 → ucon-2.2.1}/ucon/graph.py +0 -0
  60. {ucon-2.2.0 → ucon-2.2.1}/ucon/integrations/__init__.py +0 -0
  61. {ucon-2.2.0 → ucon-2.2.1}/ucon/integrations/numpy.py +0 -0
  62. {ucon-2.2.0 → ucon-2.2.1}/ucon/integrations/pandas.py +0 -0
  63. {ucon-2.2.0 → ucon-2.2.1}/ucon/integrations/polars.py +0 -0
  64. {ucon-2.2.0 → ucon-2.2.1}/ucon/integrations/pydantic.py +0 -0
  65. {ucon-2.2.0 → ucon-2.2.1}/ucon/kinds/__init__.py +0 -0
  66. {ucon-2.2.0 → ucon-2.2.1}/ucon/kinds/exceptions.py +0 -0
  67. {ucon-2.2.0 → ucon-2.2.1}/ucon/kinds/lattice.py +0 -0
  68. {ucon-2.2.0 → ucon-2.2.1}/ucon/kinds/types.py +0 -0
  69. {ucon-2.2.0 → ucon-2.2.1}/ucon/maps.py +0 -0
  70. {ucon-2.2.0 → ucon-2.2.1}/ucon/packages.py +0 -0
  71. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/__init__.py +0 -0
  72. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/aspects.py +0 -0
  73. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/dimensions.py +0 -0
  74. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/formulas.py +0 -0
  75. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/kinds.py +0 -0
  76. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/lexer.py +0 -0
  77. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/namespaces.py +0 -0
  78. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/quantity.py +0 -0
  79. {ucon-2.2.0 → ucon-2.2.1}/ucon/parsing/units.py +0 -0
  80. {ucon-2.2.0 → ucon-2.2.1}/ucon/quantity.py +0 -0
  81. {ucon-2.2.0 → ucon-2.2.1}/ucon/resolver.py +0 -0
  82. {ucon-2.2.0 → ucon-2.2.1}/ucon/serialization.py +0 -0
  83. {ucon-2.2.0 → ucon-2.2.1}/ucon/system/__init__.py +0 -0
  84. {ucon-2.2.0 → ucon-2.2.1}/ucon/units.py +0 -0
  85. {ucon-2.2.0 → ucon-2.2.1}/ucon/units.pyi +0 -0
  86. {ucon-2.2.0 → ucon-2.2.1}/ucon.egg-info/SOURCES.txt +0 -0
  87. {ucon-2.2.0 → ucon-2.2.1}/ucon.egg-info/dependency_links.txt +0 -0
  88. {ucon-2.2.0 → ucon-2.2.1}/ucon.egg-info/requires.txt +0 -0
  89. {ucon-2.2.0 → ucon-2.2.1}/ucon.egg-info/top_level.txt +0 -0
  90. {ucon-2.2.0 → ucon-2.2.1}/uv.lock +0 -0
@@ -16,6 +16,27 @@ jobs:
16
16
  fetch-depth: 0 # needed for ancestry check
17
17
  ref: ${{ github.ref_name }}
18
18
 
19
+ - name: Verify CHANGELOG has a section for this tag
20
+ if: startsWith(github.ref, 'refs/tags/')
21
+ run: |
22
+ TAG=${GITHUB_REF#refs/tags/}
23
+ # Alpha and beta tags may come from feature branches and are not
24
+ # expected to carry a released section — same exemption the
25
+ # mainline ancestry check below applies.
26
+ if echo "$TAG" | grep -qE '[0-9]+\.[0-9]+\.[0-9]+(a|b)[0-9]+$'; then
27
+ echo "Pre-release tag $TAG — skipping CHANGELOG section check."
28
+ exit 0
29
+ fi
30
+ # Dots are escaped so the pattern cannot match a near-miss header.
31
+ PATTERN="^## \[$(printf '%s' "$TAG" | sed 's/[.]/\\./g')\]"
32
+ if ! grep -q "$PATTERN" CHANGELOG.md; then
33
+ echo "::error::CHANGELOG.md has no '## [$TAG]' section."
34
+ echo "Promote the [Unreleased] section to [$TAG] before tagging,"
35
+ echo "otherwise the release is published with empty notes."
36
+ exit 1
37
+ fi
38
+ echo "Found '## [$TAG]' in CHANGELOG.md."
39
+
19
40
  - name: Install uv
20
41
  uses: astral-sh/setup-uv@v5
21
42
 
@@ -84,6 +105,12 @@ jobs:
84
105
  }
85
106
  found { print }
86
107
  ' CHANGELOG.md > release_notes.md
108
+ # Backstop: the preflight proved the header exists, so an empty
109
+ # extraction here means the section itself has no body.
110
+ if [ ! -s release_notes.md ]; then
111
+ echo "::error::Extracted release notes for $TAG are empty."
112
+ exit 1
113
+ fi
87
114
 
88
115
  - name: 📋 Create GitHub Release
89
116
  if: startsWith(github.ref, 'refs/tags/')
@@ -7,6 +7,67 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.2.1] - 2026-09-18
11
+
12
+ ### Changed
13
+
14
+ - **The publish workflow refuses to release a tag whose changelog section
15
+ is missing.** (#311) Release notes are generated by scanning
16
+ `CHANGELOG.md` for `## [<tag>]` at tag-push time. When the content was
17
+ still under `## [Unreleased]`, the scan matched nothing, wrote an empty
18
+ file, and the GitHub release was created with a blank body — silently,
19
+ with every step reporting success. Seven releases shipped that way:
20
+ `2.1.2` through `2.1.7`, plus `2.1.2a1`.
21
+
22
+ A preflight now runs before the build and before any upload, so a
23
+ missing section fails the run while it is still cheap to fix — promote
24
+ the section, move the tag, push again. Guarding after the upload would
25
+ instead leave the package public and the run red, with a re-run
26
+ skipping PyPI and failing the same check. Alpha and beta tags are
27
+ exempt, matching the mainline-ancestry check's existing exemption,
28
+ since those may come from feature branches. A second check rejects a
29
+ section header that matches but has no body.
30
+
31
+ No effect on the published package. The seven blank release bodies have
32
+ been backfilled from the changelog.
33
+
34
+ ### Fixed
35
+
36
+ - **`Number` addition and subtraction now convert operands stated in
37
+ different units.** Both operators guarded the dimension and then combined
38
+ raw magnitudes, so `parse("1 volt") - parse("1000 millivolt")` returned
39
+ `-999.0 V` while `==` reported the two equal. Any same-dimension pair with
40
+ a differing scale was affected — `1 meter - 100 centimeter`,
41
+ `1 hour - 30 minute`, `1 kilogram - 500 gram` — and the wrong value came
42
+ back silently, with no exception at any boundary.
43
+
44
+ `other` is now restated in the left operand's unit before the magnitudes
45
+ combine, using the same `_canonical_magnitude` normalization `__eq__`
46
+ already performed. That makes comparison and arithmetic agree: whenever
47
+ `a == b`, `(a - b).quantity` is zero. The rescaling is pure algebra over
48
+ `base_form` prefactors and consults no `ConversionGraph`, so additive
49
+ arithmetic still needs no active graph, and matched-unit operands take a
50
+ fast path that leaves their magnitudes bit-identical.
51
+
52
+ Uncertainty is rescaled by the same factor before quadrature. Previously
53
+ `1 V ± 0.03 V` combined with `100 mV ± 10 mV` propagated
54
+ `sqrt(0.03² + 10²)`, mixing volts with millivolts.
55
+
56
+ Units with no `base_form` — affine temperature scales, logarithmic units,
57
+ units defined only by a graph edge — normalize to themselves and so still
58
+ combine unscaled. That matches `__eq__`, which reports `1 K == 1 °C`, and
59
+ leaves the two consistent; correcting affine arithmetic is separate work.
60
+ `NumberArray` is unchanged: it refuses mismatched units uniformly across
61
+ comparison and arithmetic, which is internally coherent.
62
+
63
+ ### Documentation
64
+
65
+ - **ucon-tools docs submodule advanced to v0.9.0.** The
66
+ `docs/external/ucon-tools` pin had been frozen at 0.4.5rc1 while the
67
+ MCP-server guide and tool reference it serves into the docs site were
68
+ rewritten upstream; the published pages now describe the consolidated
69
+ discover/define/system tool surface.
70
+
10
71
  ## [2.2.0] - 2026-09-12
11
72
 
12
73
  ### Removed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ucon
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: A tool for dimensional analysis: a 'Unit CONverter'
5
5
  Author-email: "Emmanuel I. Obi" <withtwoemms@gmail.com>
6
6
  Maintainer-email: "Emmanuel I. Obi" <withtwoemms@gmail.com>
@@ -2279,7 +2279,70 @@ class Number:
2279
2279
  kind=self._resolve_mul_kind(other),
2280
2280
  )._carry(result_aspects)
2281
2281
 
2282
+ def _additive_operand(self, other: 'Number') -> tuple:
2283
+ """``other``'s quantity and uncertainty expressed in ``self.unit``.
2284
+
2285
+ Additive operations combine magnitudes, so an operand stated in a
2286
+ different unit of the same dimension has to be rescaled before the
2287
+ two can be added — otherwise ``1 volt - 1000 millivolt`` returns
2288
+ ``-999 V``.
2289
+
2290
+ The rescaling is pure algebra over :attr:`~Unit.base_form`
2291
+ prefactors, routed through :attr:`_canonical_magnitude`; no
2292
+ :class:`~ucon.graph.ConversionGraph` is consulted, so additive
2293
+ arithmetic needs no active graph. It is the same normalization
2294
+ :meth:`__eq__` performs, which is what makes ``a == b`` and
2295
+ ``a - b == 0`` agree about the same pair.
2296
+
2297
+ Returns
2298
+ -------
2299
+ tuple
2300
+ ``(quantity, uncertainty)`` in ``self.unit``. Uncertainty is
2301
+ scaled by the same factor as the quantity, and stays ``None``
2302
+ when ``other`` carries none.
2303
+
2304
+ Notes
2305
+ -----
2306
+ Operands already in ``self.unit`` are returned unchanged, so the
2307
+ common same-unit case is bit-identical to plain magnitude
2308
+ arithmetic.
2309
+
2310
+ Units with no ``base_form`` — affine temperature scales,
2311
+ logarithmic units, units defined only by a graph edge — normalize
2312
+ to themselves, so their magnitudes still combine unscaled. That
2313
+ matches :meth:`__eq__`, which reports ``1 K == 1 °C``; the two
2314
+ remain consistent, and neither is yet correct for affine scales.
2315
+ """
2316
+ if self.unit == other.unit:
2317
+ return other.quantity, other.uncertainty
2318
+
2319
+ target = Number(1.0, self.unit)._canonical_magnitude
2320
+ source = Number(1.0, other.unit)._canonical_magnitude
2321
+ if not target or not source:
2322
+ # A zero normalization factor means a malformed unit definition;
2323
+ # fall back to unscaled magnitudes rather than dividing by zero.
2324
+ return other.quantity, other.uncertainty
2325
+
2326
+ factor = source / target
2327
+ uncertainty = (
2328
+ other.uncertainty * abs(factor)
2329
+ if other.uncertainty is not None
2330
+ else None
2331
+ )
2332
+ return other.quantity * factor, uncertainty
2333
+
2282
2334
  def __add__(self, other: 'Number') -> 'Number':
2335
+ """Sum two ``Number``s, rescaling ``other`` into ``self.unit`` first.
2336
+
2337
+ Operands must share a dimension; they need not share a unit. The
2338
+ result is stated in ``self.unit``. See :meth:`_additive_operand`
2339
+ for the normalization and its limits.
2340
+
2341
+ Raises
2342
+ ------
2343
+ TypeError
2344
+ The operands' dimensions differ.
2345
+ """
2283
2346
  if not isinstance(other, Number):
2284
2347
  return NotImplemented
2285
2348
 
@@ -2294,21 +2357,36 @@ class Number:
2294
2357
  result_kind = self._resolve_add_kind(other)
2295
2358
  result_aspects = self._resolve_add_aspects(other)
2296
2359
 
2360
+ # Same dimension, possibly different unit: combine magnitudes only
2361
+ # after restating `other` in this Number's unit.
2362
+ other_quantity, other_uncertainty = self._additive_operand(other)
2363
+
2297
2364
  # Uncertainty propagation for addition: δc = sqrt(δa² + δb²)
2298
2365
  new_uncertainty = None
2299
- if self.uncertainty is not None or other.uncertainty is not None:
2366
+ if self.uncertainty is not None or other_uncertainty is not None:
2300
2367
  ua = self.uncertainty if self.uncertainty is not None else 0
2301
- ub = other.uncertainty if other.uncertainty is not None else 0
2368
+ ub = other_uncertainty if other_uncertainty is not None else 0
2302
2369
  new_uncertainty = math.sqrt(ua**2 + ub**2)
2303
2370
 
2304
2371
  return Number(
2305
- quantity=self.quantity + other.quantity,
2372
+ quantity=self.quantity + other_quantity,
2306
2373
  unit=self.unit,
2307
2374
  uncertainty=new_uncertainty,
2308
2375
  kind=result_kind,
2309
2376
  )._carry(result_aspects)
2310
2377
 
2311
2378
  def __sub__(self, other: 'Number') -> 'Number':
2379
+ """Subtract ``other``, rescaling it into ``self.unit`` first.
2380
+
2381
+ Operands must share a dimension; they need not share a unit. The
2382
+ result is stated in ``self.unit``. See :meth:`_additive_operand`
2383
+ for the normalization and its limits.
2384
+
2385
+ Raises
2386
+ ------
2387
+ TypeError
2388
+ The operands' dimensions differ.
2389
+ """
2312
2390
  if not isinstance(other, Number):
2313
2391
  return NotImplemented
2314
2392
 
@@ -2323,15 +2401,19 @@ class Number:
2323
2401
  result_kind = self._resolve_add_kind(other)
2324
2402
  result_aspects = self._resolve_add_aspects(other, op="Subtracting")
2325
2403
 
2404
+ # Same dimension, possibly different unit: combine magnitudes only
2405
+ # after restating `other` in this Number's unit.
2406
+ other_quantity, other_uncertainty = self._additive_operand(other)
2407
+
2326
2408
  # Uncertainty propagation for subtraction: δc = sqrt(δa² + δb²)
2327
2409
  new_uncertainty = None
2328
- if self.uncertainty is not None or other.uncertainty is not None:
2410
+ if self.uncertainty is not None or other_uncertainty is not None:
2329
2411
  ua = self.uncertainty if self.uncertainty is not None else 0
2330
- ub = other.uncertainty if other.uncertainty is not None else 0
2412
+ ub = other_uncertainty if other_uncertainty is not None else 0
2331
2413
  new_uncertainty = math.sqrt(ua**2 + ub**2)
2332
2414
 
2333
2415
  return Number(
2334
- quantity=self.quantity - other.quantity,
2416
+ quantity=self.quantity - other_quantity,
2335
2417
  unit=self.unit,
2336
2418
  uncertainty=new_uncertainty,
2337
2419
  kind=result_kind,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ucon
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: A tool for dimensional analysis: a 'Unit CONverter'
5
5
  Author-email: "Emmanuel I. Obi" <withtwoemms@gmail.com>
6
6
  Maintainer-email: "Emmanuel I. Obi" <withtwoemms@gmail.com>
@@ -235,6 +235,7 @@
235
235
  "tests/ucon/system/test_bridge.py",
236
236
  "tests/ucon/system/test_relations.py",
237
237
  "tests/ucon/system/test_strict_resolution.py",
238
+ "tests/ucon/test_additive_unit_conversion.py",
238
239
  "tests/ucon/test_algebra.py",
239
240
  "tests/ucon/test_base_form.py",
240
241
  "tests/ucon/test_cache.py",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "2.2.1",
3
+ "distance": 0,
4
+ "node": "g3abafc0f29cd250c8add5780329e80900564a959",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-09-18"
8
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "2.2.0",
3
- "distance": 0,
4
- "node": "ga8b5c201c4adff68ad0909d2ef29f02462444fa5",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-09-13"
8
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes