Skip to content

Commit e23f934

Browse files
FBumannclaudepre-commit-ci[bot]
authored
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/piecewise-linear-constraints.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ API
5050
method="auto", # "auto", "sos2", or "incremental"
5151
active=None, # binary variable to gate the constraint
5252
name=None, # base name for generated variables/constraints
53-
skip_nan_check=False,
5453
)
5554
5655
Creates auxiliary variables and constraints that enforce all expressions

linopy/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
PWL_FILL_SUFFIX = "_fill"
4747
PWL_BINARY_SUFFIX = "_binary"
4848
PWL_SELECT_SUFFIX = "_select"
49-
PWL_AUX_SUFFIX = "_aux"
50-
PWL_LP_SUFFIX = "_lp"
51-
PWL_LP_DOMAIN_SUFFIX = "_lp_domain"
5249
PWL_INC_BINARY_SUFFIX = "_inc_binary"
5350
PWL_INC_LINK_SUFFIX = "_inc_link"
5451
PWL_INC_ORDER_SUFFIX = "_inc_order"

0 commit comments

Comments
 (0)