Skip to content

Consolidate duplicated input-coercion helpers into _helpers#84

Merged
OVVO-Financial merged 2 commits into
mainfrom
consolidate-coercion-helpers
Jul 5, 2026
Merged

Consolidate duplicated input-coercion helpers into _helpers#84
OVVO-Financial merged 2 commits into
mainfrom
consolidate-coercion-helpers

Conversation

@gitRasheed

Copy link
Copy Markdown
Collaborator

What

Five input-validation helpers were re-defined near-identically across modules:

Helper Duplicated in Now
_as_matrix (strict 2D, finite) causation, norm, distance _helpers._as_matrix(x, name)
_as_matrix (promotes 1D to column) boost, stack _helpers._as_vector_or_matrix(x, name)
_as_point_matrix boost, stack _helpers._as_point_matrix(x, n_cols)
_as_vector (flattens any shape) boost, stack _helpers._as_flat_vector(x, name)
_as_pair (strict, finite) dependence, part _helpers._as_pair(x, y)

Each group was byte-identical modulo the name interpolated into error messages. One canonical copy of each now lives in nns._helpers; the promoting/flattening variants are renamed so the shared module distinguishes them from the strict ones. causation previously imported _as_pair from dependence and now imports it from _helpers directly.

Net: −57 lines, one source of truth per validation rule.

What deliberately did NOT move

These look similar but differ behaviorally, so they stay local:

  • co_moments._as_pair — no finite/empty checks; co-moments accept NaN/inf by design and parity edge cases depend on it
  • pm_matrix._as_matrix — no finite check
  • copula._as_matrix — enforces ≥2 columns with copula-specific messages
  • norm._as_vector / distance._as_vector — bespoke error messages (x[{i}], dist_estimate)

Verification

  • All error messages verified byte-identical to the originals (manual smoke of every changed path)
  • ruff check and mypy clean
  • Full suite: 2,234 passed locally (the two test_practical_examples compound tests that fail on this machine fail identically on unmodified main — pre-existing local-environment sensitivity, green in CI)
  • No test references any of these private helpers

Five near-identical validation helpers were re-defined per module:
_as_matrix in causation/norm/distance (strict 2D), _as_matrix in
boost/stack (1D-to-column promoting), _as_point_matrix and _as_vector
in boost/stack, and _as_pair in dependence/part. Each pair or triple
was byte-identical modulo the name interpolated into error messages.

Move one canonical copy of each into nns._helpers: _as_matrix (strict),
_as_vector_or_matrix (promoting), _as_point_matrix, _as_flat_vector,
and _as_pair. The promoting and flattening variants are renamed so the
shared module distinguishes them from the strict ones. All error
messages and validation semantics are unchanged.

Deliberate variants stay local: co_moments._as_pair (permits NaN/inf),
pm_matrix._as_matrix (no finite check), copula._as_matrix (>=2-column
rule), and the norm/distance _as_vector helpers (bespoke messages).
@OVVO-Financial OVVO-Financial merged commit 1196e98 into main Jul 5, 2026
8 checks passed
@OVVO-Financial OVVO-Financial deleted the consolidate-coercion-helpers branch July 5, 2026 15:26
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.

2 participants