Let show_components override display units for Vector-form columns#595
Conversation
Adds a unitful_variant trait that resolves a getter's unit-tagged `_unitful` companion by the struct-generator's naming convention, and threads an optional `units` kwarg through show_components/_resolve_column_accessors so callers can force every Vector-form column into one unit system instead of each column's own display_units_arg default. This lets PowerSystems stop reimplementing the Vector-column table-building path just to get unit-suffixed cells and a units override. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
IS (Sienna-Platform/InfrastructureSystems.jl#595) now supports a `units` override and unit-tagged column resolution on its Vector-column show_components path, via a new unitful_variant trait. Drop PSY's reimplementation of that table-building logic and the local _unitful_getter/_column_accessor helpers in favor of IS.unitful_variant and a thin forwarding wrapper. [sources] is pinned to the IS branch backing #595 for development; restore to IS4 once that PR merges. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## IS4 #595 +/- ##
==========================================
+ Coverage 83.85% 83.99% +0.13%
==========================================
Files 73 73
Lines 6301 6334 +33
==========================================
+ Hits 5284 5320 +36
+ Misses 1017 1014 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR enhances show_components so Vector-form additional_columns can (1) be forced into a caller-selected unit system via a new units keyword and (2) display unit-tagged values by routing unit-aware getters through a _unitful companion resolved by a new unitful_variant trait. This closes a gap versus Dict-form columns (closures) and enables downstream packages (e.g., PowerSystems) to avoid reimplementing table-building logic.
Changes:
- Added
RelativeUnits.unitful_variant(f)to resolve a getter’s*_unitfulcompanion (fallbacks tofwhen absent). - Threaded
unitsthroughshow_componentsand_resolve_column_accessorsso Vector-form columns can be uniformly overridden without forcing a units argument onto non-unit-aware getters. - Added tests covering default trait behavior, explicit
unitsoverride, column-order preservation, and “ignored for Dict-form” behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
test/test_printing.jl |
Adds coverage for Vector-form column unit resolution and units override behavior in show_components. |
src/utils/test.jl |
Extends test component getters with a display_units_arg trait and a _unitful companion to exercise the new printing path. |
src/utils/print_pt.jl |
Implements units keyword plumbing and routes unit-aware Vector columns through unitful_variant for unit-suffixed cell output. |
src/relative_units.jl |
Introduces and exports unitful_variant in RelativeUnits. |
src/InfrastructureSystems.jl |
Brings unitful_variant into the InfrastructureSystems namespace via using .RelativeUnits:. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ay in device base (#1711) * Show explicit unit suffixes for converted fields; rating fields display in device base Implements the display convention proposed in #1128: unattached components show needs_conversion fields in natural units, attached components show system base, and rating/rating_primary/rating_secondary/rating_tertiary fields always show device base regardless of attachment (a "rating" isn't scaled by the system the device happens to sit on). Every converted value now prints with an explicit unit suffix (e.g. "30.0 MW", "1.0 DU", "0.3 SU") by displaying the getter's `_unitful` companion instead of a bare number. Also adds a `units` keyword to the new `show_component` function and to `show_components` to force a specific display unit system per call. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * code review * Delegate show_components Vector-form columns to IS IS (Sienna-Platform/InfrastructureSystems.jl#595) now supports a `units` override and unit-tagged column resolution on its Vector-column show_components path, via a new unitful_variant trait. Drop PSY's reimplementation of that table-building logic and the local _unitful_getter/_column_accessor helpers in favor of IS.unitful_variant and a thin forwarding wrapper. [sources] is pinned to the IS branch backing #595 for development; restore to IS4 once that PR merges. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * Pin IS [sources] to a commit SHA instead of a branch name A branch name under [sources] can move underneath this PR (force-push, new commits) without CI or reviewers noticing; a SHA is immutable, so the pin only changes when this PR is explicitly updated to track IS PR #595's latest commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: jd-lara <jdlara@berkeley.edu>
Summary
IS.unitful_variant(f)trait that resolves a getter's unit-tagged_unitfulcompanion by the struct-generator's naming convention (falls back tofwhen no companion is registered).unitskwarg throughshow_components/_resolve_column_accessorsso callers can force every Vector-form column into one unit system instead of resolving each column's owndisplay_units_argdefault.unitful_variantso cells print with an explicit unit suffix (e.g."5 SU"), matching the Dict-form behavior domain packages already build with closures.Motivation
PowerSystems (psy6, see the units-management rework) needed a
show_components(sys, T, [:field, ...]; units = MW)API that both (a) forces a caller-chosen unit system across all columns and (b) prints unit-tagged values, not bare numbers. Neither capability existed on IS's Vector-column path, so PSY reimplemented ~35 lines ofshow_components's table-building logic (column labels, thecomps/dataloop, thepretty_tablecall) just to get them. This PR moves both capabilities into IS so PSY (and other domain packages) can go back to a thin forwarding wrapper.Test plan
julia --project=test test/runtests.jl(IS): 8672 tests, 0 failurestest/test_printing.jltestset covers: trait-default resolution with unit suffix, explicitunitsoverride, Vector column order preservation,unitssilently ignored for Dict-form columns[sources]to this branch):test/runtests.jl test_printing— 74 passed, 0 failed (1 unrelated pre-existingPowerSystemCaseBuilderdata-build failure, reproduced identically againstIS4directly)🤖 Generated with Claude Code