Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
|
For a similar reason, in SpikeInterface, we keep an action on github measuring import time for the different modules: https://github.com/SpikeInterface/spikeinterface/blob/main/.github/workflows/test_imports.yml https://github.com/SpikeInterface/spikeinterface/blob/main/.github/scripts/import_test.py This avoids regression. With time, I have come to love the simplicity of delayed imports with just an import x on the spot where it is needed. Honestly, the downsides are 99 % aesthetical but you learn to get over them. |
gviejo
approved these changes
Feb 24, 2026
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
scipy.signal,scipy.spatial,xarray) inside functions to reduceimport pynappletimeBackground
As developers, we discussed using
lazy_loader.loadfrom scientific-python/lazy_loader but decided against it for this package because:We recognize that the current pattern of moving imports inside functions is suboptimal (slight overhead on first function call, repeated import statements). However, we defer adoption of
lazy_loaderuntil it proves itself stable across the ecosystem. We already have it as a dependency in nemos, which will serve as a testing ground.Changes
scipy.signalimports moved inside functions in:core/time_series.py(smooth,decimatemethods)core/_core_functions.py(_convolve)process/filtering.py(already done)process/spectrum.py(compute_mean_power_spectral_density)scipy.spatial.distance.cdistimport moved insideprocess/decoding.pyxarrayimports moved inside wrapper functions in:process/decoding.pyprocess/tuning_curves.py(already done)test_lazy_import_heavy_modulesto ensure these modules aren't loaded at import timePerformance
Speedup: ~2.4x faster (57% reduction)
Additional fix
test_compute_1d_mutual_infoandtest_compute_2d_mutual_infotests intests/test_tuning_curves.pynp.testing.assert_approx_equaltonp.testing.assert_allclose(lines 1591, 1663)assert_approx_equalis for scalars only; numpy 2.4.2 (used in CI) enforces this strictly, causingTypeError: only 0-dimensional arrays can be converted to Python scalars