Commit e23f934
refac: clean up piecewise module (#641)
* refac: use _to_linexpr in tangent_lines instead of manual dispatch
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: rename _validate_xy_points to _validate_breakpoint_shapes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: clean up duplicate section headers in piecewise.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: convert expressions once in _broadcast_points
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: remove unused _compute_combined_mask
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: validate method early, compute trailing_nan_only once
Move method validation to add_piecewise_constraints entry point and
avoid calling _has_trailing_nan_only multiple times on the same data.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: deduplicate stacked mask expansion in _add_continuous_nvar
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: remove redundant isinstance guards in tangent_lines
_coerce_breaks already returns DataArray inputs unchanged.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: rename _extra_coords to _var_coords_from with explicit exclude set
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: clarify transitive validation in breakpoint shape check
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: remove skip_nan_check parameter
NaN breakpoints are always handled automatically via masking.
The skip_nan_check flag added API surface for minimal value —
it only asserted no NaN (misleading name) and skipped mask
computation (negligible performance gain).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: remove unused PWL_AUX/LP/LP_DOMAIN constants
Remnants of the old LP method that was removed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: always return link constraint from incremental path
Both SOS2 and incremental branches now consistently return the
link constraint, making the return value predictable for callers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: split _add_continuous into _add_sos2 and _add_incremental
Extract the SOS2 and incremental formulations into separate functions.
Add _stack_along_link helper to deduplicate the expand+concat pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: rename test classes to match current function names
TestPiecewiseEnvelope -> TestTangentLines
TestSolverEnvelope -> TestSolverTangentLines
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: use _stack_along_link for expression stacking
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: use generic param names in _validate_breakpoint_shapes
Rename x_points/y_points to bp_a/bp_b to reflect N-variable context.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: extract _to_seg helper in tangent_lines for rename+reassign pattern
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: extract _strip_nan helper for NaN filtering in slopes mode
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: extract _breakpoints_from_slopes, add _to_seg docstring
Move the ~50 line slopes-to-points conversion out of breakpoints()
into _breakpoints_from_slopes, keeping breakpoints() as a clean
validation-then-dispatch function.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: resolve mypy errors in _strip_nan and _stack_along_link types
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: remove duplicate slopes validation in breakpoints()
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* refac: move _rename_to_segments to module level, fix extra blank line
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test: add validation and edge-case tests for piecewise module
Cover error paths and edge cases: non-1D input, slopes mode with
DataArray y0, non-numeric breakpoint coords, segment dim mismatch,
disjunctive >2 pairs, disjunctive interior NaN, expression name
fallback, incremental NaN masking, and scalar coord handling.
Coverage: 92% -> 97%
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: resolve ruff and mypy errors
- Use `X | Y` instead of `(X, Y)` in isinstance (UP038)
- Remove unused `dim` variable in _add_continuous (F841)
- Fix docstring formatting (D213)
- Remove unnecessary type: ignore comment
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 07b7c16 commit e23f934
4 files changed
Lines changed: 418 additions & 288 deletions
File tree
- doc
- linopy
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 49 | | |
53 | 50 | | |
54 | 51 | | |
| |||
0 commit comments