Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow model opts #950

Merged
merged 5 commits into from
Apr 15, 2024
Merged

Allow model opts #950

merged 5 commits into from
Apr 15, 2024

Conversation

newville
Copy link
Member

@newville newville commented Apr 8, 2024

Description

This restores the behavior of setting a non-default keyword value for a Model function argument when creating a Model. That is, in 1.3.0,

from lmfit import Model
from lmfit.lineshapes import step

mymodel  = Model(step, form='erf')

could sometimes fail to set the form to erf. This is true in StepModel, for example, as it set the independent variables to ['x'].

The fix here is sort of "belt and suspenders" in that: the form above should normally work in 1.3.0, but now that new default value (held in Model.opts = {'form': 'erf'}) is used, and then any independent variables are set, and then any runtime keyword arguments.

See #947

Not being able to leave well enough alone, I also tweaked Model.__repr__() to use Model._reprsting() and to use long=True by default. With this, for example, the repr for StepModel will always show the form.

This can be squashed-and-merged or the repr string change can be removed.

Type of Changes
  • Bug fix
  • New feature
  • Refactoring / maintenance
  • Documentation / examples
Tested on

Python: 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:35:23) [Clang 15.0.7 ]

lmfit: 1.3.0.post2+gcf2626b.d20240407, scipy: 1.12.0, numpy: 1.26.4, asteval: 0.9.32, uncertainties: 3.1.7

Verification

Have you

  • included docstrings that follow PEP 257?
  • referenced existing Issue and/or provided relevant link to mailing list?
  • verified that existing tests pass locally?
  • verified that the documentation builds locally?
  • squashed/minimized your commits and written descriptive commit messages?
  • added or updated existing tests to cover the changes?
  • updated the documentation and/or added an entry to the release notes (doc/whatsnew.rst)?
  • added an example?

@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.20%. Comparing base (cf2626b) to head (217347e).

Files Patch % Lines
lmfit/model.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
+ Coverage   93.14%   93.20%   +0.05%     
==========================================
  Files          10       10              
  Lines        3762     3765       +3     
==========================================
+ Hits         3504     3509       +5     
+ Misses        258      256       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@newville
Copy link
Member Author

@reneeotten I'd like to merge this (or a reviewed version of it) and tag as 1.3.1 over the next week or so. Any objections?

@reneeotten
Copy link
Contributor

@reneeotten I'd like to merge this (or a reviewed version of it) and tag as 1.3.1 over the next week or so. Any objections?

@newville I'll take a look tonight after work.

Copy link
Contributor

@reneeotten reneeotten left a comment

Choose a reason for hiding this comment

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

sorry for the delay @newville .... Changes look fine to me, the only suggestion I would have is to completely remove all type annotations in the added test and perhaps reorganize/minimize the commits a bit so that it's clear what is fixing the two issues. But that does likely require a bit of git-voodoo and I know you're not so keen on that ;) Anyway, the code changes look good to me and to be honest you know that code much better than me - so feel free to merge!

tests/test_model.py Outdated Show resolved Hide resolved
tests/test_model.py Outdated Show resolved Hide resolved
tests/test_model.py Outdated Show resolved Hide resolved
…nd 'kwargs' as for variadic function, add test
@newville
Copy link
Member Author

@reneeotten Thanks! I backed up and did a forced push for one commit to address #953. I think this is probably OK to leave as a few separate commits rather than squash-and-merge. Assuming the tests pass, I'll plan on merging in a day or so.
I would then rebase to get #952 (maybe with more tweaks) merged, then call that 1.3.1.

@newville
Copy link
Member Author

OK, merging this...

@newville newville merged commit de35309 into master Apr 15, 2024
12 checks passed
@newville newville deleted the allow_model_opts branch July 13, 2024 14:00
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.

3 participants