Skip to content

Lazy import#160

Merged
ericpre merged 18 commits intohyperspy:mainfrom
ericpre:lazy_import
Apr 9, 2026
Merged

Lazy import#160
ericpre merged 18 commits intohyperspy:mainfrom
ericpre:lazy_import

Conversation

@ericpre
Copy link
Copy Markdown
Member

@ericpre ericpre commented Jan 16, 2026

This PR will need hyperspy/hyperspy#3569 to be release and I opened it to try if hyperspy/hyperspy#3569 works well.

All signals import are now ~0.3s.

Progress of the PR

  • Implement lazy import using lazy-loader,
  • refactor exspy.utils to avoid import redirection,
  • [n/a] docstring updated (if appropriate),
  • [n/a] update user guide (if appropriate),
  • update tests,
  • add a changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting of the changelog entry (and eventual user guide changes) in the docs/readthedocs.org:exspy build of this PR (link in github checks)
  • ready for review.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 83.93178% with 358 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.33%. Comparing base (1e33c62) to head (341ecd1).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
exspy/signals/_eels.py 77.77% 102 Missing and 54 partials ⚠️
exspy/signals/_eds.py 86.26% 27 Missing and 26 partials ⚠️
exspy/signals/_eds_tem.py 81.72% 28 Missing and 25 partials ⚠️
exspy/signals/_eds_sem.py 59.79% 30 Missing and 9 partials ⚠️
exspy/utils/eels/dielectric.py 70.73% 8 Missing and 4 partials ⚠️
exspy/utils/eds/_xray_lines.py 93.16% 5 Missing and 3 partials ⚠️
exspy/utils/eds/_quantification.py 93.91% 3 Missing and 4 partials ⚠️
exspy/_misc/eels/tools.py 0.00% 5 Missing ⚠️
exspy/signals/_dielectric_function.py 84.84% 3 Missing and 2 partials ⚠️
exspy/utils/eds/_particle_matter_interaction.py 81.25% 1 Missing and 2 partials ⚠️
... and 13 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
- Coverage   88.86%   88.33%   -0.54%     
==========================================
  Files          79      100      +21     
  Lines        7652     7764     +112     
  Branches      910      932      +22     
==========================================
+ Hits         6800     6858      +58     
- Misses        578      632      +54     
  Partials      274      274              

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

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

@ericpre
Copy link
Copy Markdown
Member Author

ericpre commented Mar 20, 2026

@jlaehne, @CSSFrancis, would you be able to review this PR?

Comment thread exspy/utils/eds/_quantification.py
Comment thread exspy/_misc/eels/gosh_source.py
Comment thread exspy/utils/eds/_geometry.py
@ericpre
Copy link
Copy Markdown
Member Author

ericpre commented Mar 22, 2026

Checking the integration test suite, I added back the signals submodules (for example, exspy.signals.eels) because it is used in atomap and hy - even if following the API reference, it should be imported from exspy.signals and not their submodules.

The remaining failure (hyperspy_gui_ipywidgets) is fixed in hyperspy/hyperspy_gui_ipywidgets#96.

@ericpre ericpre requested a review from jlaehne March 22, 2026 11:41
@jlaehne
Copy link
Copy Markdown
Member

jlaehne commented Mar 22, 2026

The remaining failure (hyperspy_gui_ipywidgets) is fixed in hyperspy/hyperspy_gui_ipywidgets#96.

I merged the corresponding PR. LGTM if the tests pass, @CSSFrancis do you want to have another quick look?

@ericpre ericpre force-pushed the lazy_import branch 2 times, most recently from 9c285bf to 5c66672 Compare March 28, 2026 12:41
@ericpre
Copy link
Copy Markdown
Member Author

ericpre commented Mar 29, 2026

@CSSFrancis, in case, you want to have a look, this is a large PR, but I think that it worth checking is the API reference: https://exspy--160.org.readthedocs.build/en/160/reference/index.html and privatized imports. The integration test suite passed except that hyperspy_gui_ipywidgets needs a release to include hyperspy/hyperspy_gui_ipywidgets#96.

The rest is moving import around to defer import, etc. and implementing lazy loading using lazy_loader.

@ericpre ericpre merged commit 2b27ab2 into hyperspy:main Apr 9, 2026
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants