Skip to content

Incremental improvements: refactors, edge cases, robustness#12

Open
defnalk wants to merge 5 commits intomainfrom
review/incremental-improvements
Open

Incremental improvements: refactors, edge cases, robustness#12
defnalk wants to merge 5 commits intomainfrom
review/incremental-improvements

Conversation

@defnalk
Copy link
Copy Markdown
Owner

@defnalk defnalk commented Apr 9, 2026

Summary

Five atomic improvements targeting real edge cases and clearer error surfaces. All 130 existing tests remain green.

Commits

  • fix(lambda): return 400 on ValueError from analyse_exchanger — physical/domain errors were being surfaced as 500 Internal Server Error; now correctly treated as client errors alongside TypeError.
  • fix(pump): reject zero-variance pump speeds in regression fitsscipy.stats.linregress silently returns NaN on zero-variance x; users saw an opaque r_squared post-init failure instead of the real cause.
  • fix(utils): reject non-finite values in summarise_array — a single NaN poisoned all returned statistics silently, masking upstream transmitter dropouts.
  • fix(heat_transfer): validate nonzero driving force in analyse_exchanger — equal hot/cold inlets arbitrarily tagged MEA as hot and eventually blew up deep in effectiveness(); now fails up front with a clear message.
  • fix(pump): guard ExponentialLevelModel.invert against k == 0 — flat fits leaked ZeroDivisionError through safe_pump_speed.

Test plan

  • pytest -x -q green after each commit (130 passed)

defnalk and others added 5 commits April 9, 2026 20:54
analyse_exchanger raises ValueError for caller-correctable inputs
(non-positive flows, LMTD temperature crossover, unknown flow_direction).
Previously these propagated to the broad Exception handler and produced
500 responses, obscuring client errors in logs and metrics. Treat them
as 400 Bad Request alongside the existing TypeError case.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
scipy.stats.linregress silently returns NaN slope/intercept/r when the
x-vector has zero variance, producing a fitted model whose predict() and
invert() emit NaN and whose ExponentialLevelModel.__post_init__ raises
an opaque r_squared validation error. Detect the degenerate input up
front and raise a clear ValueError pointing at the real cause.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
A single NaN in the input poisons mean/std/min/max, returning NaN
statistics without any warning and silently masking upstream data-
quality problems (e.g. transmitter dropouts). Fail loudly with a
message that tells the caller how many bad samples were found so
they can decide whether to clean or mask the data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the MEA and utility inlets are equal, the existing hot/cold
selection arbitrarily tags MEA as the hot stream and the call eventually
fails deep inside effectiveness() with "inlet temperatures are equal;
effectiveness is undefined". Detect the condition at the entry point so
the error message names the actual offending inputs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
If a caller constructs or fits a flat exponential level model (k = 0),
invert() would raise ZeroDivisionError from the math.log(...)/self.k
expression. That leaks an implementation detail and, when invoked from
safe_pump_speed(), aborts the commissioning analysis with a traceback
that doesn't explain the root cause. Detect the degenerate slope and
raise a ValueError describing why inversion is ill-posed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant