Skip to content

feat: export the fitbase API from diffpy.srfit - #218

Merged
sbillinge merged 3 commits into
diffpy:mainfrom
cadenmyers13:export-fitbase-api
Oct 8, 2026
Merged

sbillinge merged 3 commits into
diffpy:mainfrom
cadenmyers13:export-fitbase-api

Conversation

@cadenmyers13

Copy link
Copy Markdown
Contributor

Claude's words:
Re-export the public fitbase classes so from diffpy.srfit import FitRecipe works, and use the shorter import in the tests and core examples. Import pyplot lazily in plot_recipe and apply the bg-style stylesheet only to srfit's own figures, so importing srfit is faster and no longer changes the user's global matplotlib style.

Caden's words:
Three things are changed here:

  1. Commonly used classes FitRecipe, FitContribution, etc. can now be imported directly from diffpy.srfit. I did this to make srfit/cmi a bit more user friendly and cleaner. They can still be imported from diffpy.srfit.fitbase too.
  2. matplotlib was being imported on every call of FitRecipe which is not necessary and heavy. Lazy importing it makes it only imported on a plot_recipe call
  3. When FitRecipe is used, the global MPL parameters are changed to bg-style. We do not want to be changing user's default plotting styles. Now, the bg-style is only used when plot_recipe is called and the global mpl parameters are left unchanged. This is achieved through a lazy import and a test is added for this behavior change.

cadenmyers13 and others added 2 commits October 8, 2026 13:13
Re-export the public fitbase classes so `from diffpy.srfit import
FitRecipe` works, and use the shorter import in the tests and core
examples. Import pyplot lazily in plot_recipe and apply the bg-style
stylesheet only to srfit's own figures, so importing srfit is faster and
no longer changes the user's global matplotlib style.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.73%. Comparing base (a9eae82) to head (58f10af).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #218       +/-   ##
===========================================
+ Coverage   71.63%   82.73%   +11.10%     
===========================================
  Files          25       27        +2     
  Lines        3437     4182      +745     
===========================================
+ Hits         2462     3460      +998     
+ Misses        975      722      -253     
Files with missing lines Coverage Δ
tests/conftest.py 91.19% <100.00%> (+2.78%) ⬆️
tests/test_contribution.py 99.58% <100.00%> (+0.06%) ⬆️
tests/test_fitrecipe.py 99.86% <100.00%> (+0.09%) ⬆️
tests/test_fitresults.py 99.35% <100.00%> (+0.94%) ⬆️
tests/test_profile.py 99.54% <100.00%> (+0.21%) ⬆️
tests/test_profilegenerator.py 97.91% <100.00%> (-0.05%) ⬇️
tests/test_profileparser.py 100.00% <100.00%> (ø)
tests/test_recipeorganizer.py 99.53% <100.00%> (-0.16%) ⬇️
tests/test_weakrefcallable.py 98.91% <100.00%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for review

@sbillinge

Copy link
Copy Markdown
Contributor

I like this change. I think it would be good to look at putting the plotting code insde a context manager so the style changes are localized. Shall we make a n issue on this?

@sbillinge
sbillinge merged commit 0d27c41 into diffpy:main Oct 8, 2026
7 checks passed
@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge This is in a context manager, no?

        with plt.style.context(all_styles["bg-style"]):
            for name, contrib in self._contributions.items():
                profile = contrib.profile
                x = profile.x
                yobs = profile.y
                ycalc = profile.ycalc
                show_fit = plot_params["show_fit"]
                show_diff = plot_params["show_diff"]
                if ycalc is None:
...

@cadenmyers13
cadenmyers13 deleted the export-fitbase-api branch October 8, 2026 18:07
@sbillinge

Copy link
Copy Markdown
Contributor

@sbillinge This is in a context manager, no?

        with plt.style.context(all_styles["bg-style"]):
            for name, contrib in self._contributions.items():
                profile = contrib.profile
                x = profile.x
                yobs = profile.y
                ycalc = profile.ycalc
                show_fit = plot_params["show_fit"]
                show_diff = plot_params["show_diff"]
                if ycalc is None:
...

yes, that's right. If all our plotting code is encapsulated like this we are not affecting people's global style files. So either everythign is encapuslated and we aren't updating global styles, or there is some leakage somewhwere and we just remove the leaks.

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge Yeah, that was added in this PR so were good. no more leakage

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.

2 participants