Proper DeprecationWarning for 'f' cone + tighten settings validation#199
Merged
Conversation
- The 'f' cone field deprecation notice was printed via scs_printf to
stdout, so users couldn't filter, capture, or promote it to an error.
Switched to PyErr_WarnEx(PyExc_DeprecationWarning, ...), which
integrates with warnings.filterwarnings and pytest.warns.
- Tighten SCS_init parameter checks to match SCS's own validate() in
scs_source/src/scs.c. Previously the Python checks rejected only
strictly negative values for max_iters, alpha, rho_x,
acceleration_interval, m, n — then SCS's own validate would reject
zero later with a generic "ScsWork allocation error" message. Now
users get a specific Python ValueError naming the offending setting:
* m, n, max_iters, acceleration_interval, rho_x: tightened to `<= 0`
* alpha: tightened to `<= 0 || >= 2` (message: "must be in (0, 2)")
* eps_abs/rel/infeas: behavior unchanged (< 0 still rejected, zero
still accepted), but messages corrected from "positive" to
"nonnegative" to match the actual behavior.
- Tests added for the DeprecationWarning (both default and
filterwarnings("error") paths) and for each tightened bound.
Co-Authored-By: Claude Opus 4.7 <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
Two independent cleanups surfaced during the `scsobject.h` review:
1. `f` cone deprecation is now a real Python warning
The deprecation notice for the old `'f'` cone field was being printed via `scs_printf` to stdout. That meant users couldn't:
Switched to `PyErr_WarnEx(PyExc_DeprecationWarning, ...)`, so it integrates with the standard `warnings` machinery and `pytest.warns`. If the warning has been promoted to an error (e.g. `warnings.filterwarnings("error")`), `SCS_init` cleans up and returns `-1` with the exception propagated.
2. Tighten settings validation
Previously the Python-side checks in `SCS_init` rejected only strictly negative values for several settings. Zero would slip through Python and get rejected later by SCS's own `validate()` (in `scs_source/src/scs.c`), surfacing as a generic "ScsWork allocation error" without naming the bad setting.
Tightened to match SCS's actual rules and corrected the messages:
Test plan