Incremental improvements: refactors, edge cases, robustness#12
Open
Incremental improvements: refactors, edge cases, robustness#12
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five atomic improvements targeting real edge cases and clearer error surfaces. All 130 existing tests remain green.
Commits
scipy.stats.linregresssilently returns NaN on zero-variance x; users saw an opaquer_squaredpost-init failure instead of the real cause.effectiveness(); now fails up front with a clear message.ZeroDivisionErrorthroughsafe_pump_speed.Test plan
pytest -x -qgreen after each commit (130 passed)