Skip to content

Clear stale derivative kwargs when switching methods - #700

Open
ktz03 wants to merge 2 commits into
dynamicslab:mainfrom
ktz03:fix/replace-derivative-kwargs-0203
Open

ktz03 wants to merge 2 commits into
dynamicslab:mainfrom
ktz03:fix/replace-derivative-kwargs-0203

Conversation

@ktz03

@ktz03 ktz03 commented Oct 16, 2026

Copy link
Copy Markdown

Fixes #546, reported by @djpasseyjr.

SINDyDerivative.set_params(kwargs=...) merges the requested dictionary into the previous method's configuration. Switching from Savitzky–Golay to trend filtering therefore passes obsolete left/right arguments to Lasso and raises TypeError. Other method switches leave stale parameters in get_params().

Clear the previous method's arguments when kind changes, then apply the requested parameters. Keep incremental updates for the same method, including partial and empty dictionaries and replacing the differentiation method before setting its parameters. Add four method-switch regressions, a nested SINDy.set_params/fit regression and three compatibility controls for the existing nested kwargs interface introduced in #207.

Validation on Windows, Python 3.12.14, NumPy 2.5.4, scikit-learn 1.9.1 and derivative 0.6.3:

  • Differentiation and SINDy model tests (test/test_differentiation.py test/test_pysindy.py) with identical added tests: baseline 5 failed/124 passed; fixed 129 passed. Existing cross-validation scoring warnings remain; this change does not repair that separate scoring issue.
  • Thirty public method configurations: 16 stale-configuration cases become correct, and all 14 previously working cases retain identical outputs. The reported nested model fit now matches a fresh estimator; caller arrays and parameter mappings remain unchanged.
  • Eight additional public controls for partial/empty updates, no-argument calls and the original report's working method-replacement approach retain identical outputs on the baseline and fixed versions.
  • Official pre-commit checks pass for the two changed files.

The full repository suite, documentation build, other platforms and performance were not tested.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T03:21:42.359339Z 4774fc2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78d0184a71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +58 to +59
if kwargs.get("kind", self.kwargs.get("kind")) != self.kwargs.get("kind"):
self.kwargs = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve staged kwargs when assigning the initial kind

When callers stage a method's options before selecting it—for example, d = SINDyDerivative(k=2); d.set_params(kwargs={"kind": "finite_difference"})—self.kwargs has no current kind, so this condition is true and the reset silently discards k; differentiation then uses a default value, or methods with required options fail. The constructor permits an unset kind and set_params previously supported incremental kwargs, so the reset should apply only when an existing, different kind is being replaced.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial kind assignment now retains staged options; old parameters are cleared only when an existing kind changes. Added four regression cases covering finite differences, Savitzky–Golay, splines and trend filtering. The two relevant test files pass all 133 tests, and the applicable pre-commit checks pass.

This branch has not been deployed

No deployments
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.

[BUG] Parameter Carryover in SINDyDerivative from set_params. (And a minor dependency conflict with the default Google colab runtime)

1 participant