Skip to content

fix(spec): one number rule for the spec reader and the Python API - #570

Merged
Alpha9463 merged 3 commits into
mainfrom
fix/536-fix-spec-floating-accpetance
Oct 2, 2026
Merged

Alpha9463 merged 3 commits into
mainfrom
fix/536-fix-spec-floating-accpetance

Conversation

@Alpha9463

Copy link
Copy Markdown
Owner

Summary

Makes the spec reader and the Python API apply one rule to numbers. The reader accepted only exact int/float, so numpy.int64 from pandas was refused after the Python API had drawn a correct sheet from it. Meanwhile the Python API accepted values that crashed the render: Decimal geometry, non-text stream styles and numeric labels. Numpy numbers now round-trip; values layout cannot use are refused when set; numeric labels draw as text. No drawing changes.

Related Issues

Closes #536
Refs: #533, #534

Changes

How to Test

python3 -m pytest -q tests/test_stated_values.py tests/test_spec.py
python3 -c "from decimal import Decimal; from pandid import units as U; U.Pump('P-1', width=Decimal(70))"   # TypeError naming width
python3 -m pytest -q
python3 -m ruff check .
python3 -m ruff format --check tests
python3 -m mypy pandid
python3 -m pyright pandid

Evidence

Every numeric field the spec reads was tried with numpy.int64, numpy.float64 and Decimal, through the Python API, to_svg, to_drawio, to_dict and from_dict.

Before After
numpy values: Python API draws draws
numpy values: reader int64 refused on most fields round-trips; the whole sheet's SVG is identical after to_dict/from_dict
Decimal in geometry accepted, then TypeError mid-render TypeError when set; refused by the reader
Decimal in components/properties drawn, refused by the reader drawn and round-trips
color=True, dasharray=4 render crash (SVG or draw.io) TypeError when set
numeric reference, sheet_drawing_number, sheet_subtitle render crash drawn as text
  • Drawings unchanged: frames, routes and validation findings are identical to main for 46 drawings (the 21 examples as authored and with placement stripped, plus four benchmark sheets).
  • Full suite: 11,548 passed, 188 skipped.
  • Lint and types: ruff, test formatting, mypy and git diff --check are clean. Pyright reports 0 errors plus the existing __all__ warning, and 0 errors on the test file.

Not changed

  • Decimal counts (trays, feed_stages, n_inlets) still fail at construction with Python's own TypeError.
  • Decimal stream-table widths and font size draw through the Python API and are still refused by the reader.
  • Numpy values written by to_dict() are not converted, so json.dumps of such a spec fails.

Checklist

  • Base branch is main and the branch is mergeable
  • Commit subjects follow Conventional Commits; tracked work links its issue
  • Self-reviewed the full diff on the Files changed tab
  • Relevant local checks pass; all CI jobs pass before merge
  • Documentation and examples updated if behaviour changed
  • Before/after drawings included if rendered output changed (no rendered output changed)
  • Blocking review feedback resolved, if review was requested

🤖 Generated with Claude Code

The numeric readers tested isinstance(value, (int, float)) exactly, so numpy.int64 from a pandas column was refused after the Python API had drawn a correct sheet from it. They now accept any numbers. Real, and whole-number fields any numbers.Integral, still excluding bool and still returning values unchanged. Decimal is accepted for line-number components and stream properties, which are only displayed, and remains
refused for geometry, which cannot be computed with it.

Refs: #536
A Decimal size, pin coordinate, via() waypoint or annotation layout field was accepted and crashed the render. They are now refused when set, through shared checks the spec reader also uses, and pin() ranks
must be whole numbers. Stream color and dasharray must be text, since a bool or number broke the SVG or draw.io output. A numeric flag
reference, table-sheet drawing number or subtitle is drawn as text, as title-block fields are. Also restore the docs/api.md note on integer number starts left out of the #533 commit.

Refs: #536
Before Python 3.12 a Fraction cannot be formatted with ":g", and the renderers write every coordinate that way, so a Fraction size or position crashed the render on 3.10 and 3.11. The real-number rule now takes int, float and non-rational reals such as numpy floats, and
refuses Fraction alongside Decimal on every Python version.

Refs: #536
@Alpha9463
Alpha9463 merged commit 54baa1d into main Oct 2, 2026
7 checks passed
@Alpha9463
Alpha9463 deleted the fix/536-fix-spec-floating-accpetance branch October 2, 2026 03:42
@Alpha9463 Alpha9463 self-assigned this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The spec reader refuses numpy and Decimal numbers the Python door accepts and draws

1 participant