Skip to content

🐛 resolve get_physical_dim across multiple bases when unambiguous - #483

Open
xroynard wants to merge 4 commits into
mainfrom
fix/physical-dim-multibase
Open

🐛 resolve get_physical_dim across multiple bases when unambiguous#483
xroynard wants to merge 4 commits into
mainfrom
fix/physical-dim-multibase

Conversation

@xroynard

Copy link
Copy Markdown
Contributor

Context

Fixes #482.

Sample.get_physical_dim() currently delegates base resolution to resolve_base(), which raises as soon as a Sample holds more than one base and no default base is set. This forces callers to set a default base even when the answer is unambiguous.

The physical dimension is stored per base in the CGNS datamodel (the 2nd integer of the CGNSBase_t node value, set by newCGNSBase in init_base), and nothing constrains different bases to agree. However, in the overwhelming majority of real Samples all bases do share the same physical dimension (e.g. a volume base and its surface/line boundary bases all live in the same ambient space). So requiring a default base in that case is unnecessary friction.

Change

get_physical_dim(base=None) now:

  • collects the physical dimension of every base (ignoring the special Global base);
  • returns the common value when all bases agree — no default base needed;
  • raises a clear ValueError asking the caller to specify a base only when the physical dimensions actually differ across bases.

Passing an explicit base keeps the previous behaviour unchanged. get_topological_dim() is intentionally left as-is: topological dimensions legitimately differ between bases (a 3D volume base vs. a 2D surface base), so the ambiguity there is real.

This is backward compatible: previously-working calls keep working, and calls that used to raise on multi-base Samples now succeed when the value is unambiguous.

Tests

Added test_get_physical_dim_multibase (agreeing bases → common value returned, topological dim still raises) and test_get_physical_dim_multibase_diverging (differing bases → explicit ValueError, explicit base resolves it).

xroynard added 2 commits July 31, 2026 10:33
…biguous

get_physical_dim previously delegated base resolution to resolve_base,
which raises when several bases exist and no default is set. But the
physical dimension is a per-base CGNS attribute that bases very often
share, so the ambiguity is not always real. When no base is given and
every base agrees on the physical dimension, return that common value;
only raise (with an explicit message) when the dimensions actually
differ. Passing an explicit base keeps the previous behaviour.
@xroynard
xroynard requested a review from a team as a code owner July 31, 2026 08:40
@xroynard xroynard changed the title fix: resolve get_physical_dim across multiple bases when unambiguous 🐛 resolve get_physical_dim across multiple bases when unambiguous Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment on lines +757 to +759
try:
base = self.resolve_base(base, time)
except KeyError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have an explicit branching instead of relying on try/except ?

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.

Error asking to set a default base when calling Sample.get_physical_dim()

3 participants