Repository navigation
refactor(api): decouple optional dependency imports and support minimal base installation - #13
Merged
Merged
Conversation
- Promote river to core dependencies in pyproject.toml as foundational streaming drift engine - Enhance OptionalDependencyError to produce clear, actionable pip install extra suggestions - Guard optional imports (umap-learn, shap, lime, pyclustering, hdbscan, tensorflow, matplotlib, seaborn, click) across core modules - Add lazy import wrappers raising OptionalDependencyError on actual usage
… tests - Validate clean top-level import of stride without optional packages in sys.modules - Validate core estimators and analyzers execute on pure base dependencies - Validate OptionalDependencyError triggers with actionable install hints for missing optional features
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
riverto core dependencies inpyproject.tomlas it is the foundational streaming generator and drift descriptor engine for STRIDE.umap-learn,shap,lime,pyclustering,hdbscan,tensorflow,matplotlib,seaborn,click) soimport stridesucceeds in a clean base environment without optional dependencies.OptionalDependencyErrorwith standardized, actionable installation guidance (pip install stride-xai[extra]).tests/test_minimal_install_import.pyverifying clean minimal import, base execution, and properOptionalDependencyErrorguardrails.Motivation
stride-xaiin a minimal environment failed atimport stridewithModuleNotFoundErrordue to eager top-level imports of optional libraries (umap-learn,shap,lime,matplotlib,pyclustering, etc.).Key Changes
1. Dependency Specifications & Error Handling
pyproject.toml: Moved"river"into coredependencieswhile retainingdrift = ["river"]in[project.optional-dependencies].src/stride/exceptions.py: UpdatedOptionalDependencyErrorto accept(package_name, feature_name, extra_name=None)and output actionable pip install hints.2. Optional Import Decoupling
src/stride/common/__init__.py: Lazily imported UMAP in_create_reducer(), raisingOptionalDependencyErrorwithextra_name="clustering".src/stride/xai/importance/methods.py: Lazily importedshapandlimewithin_calculate_shapand_calculate_lime, raisingOptionalDependencyErrorwithextra_name="xai".src/stride/xai/clustering/xmeans.py: Lazily importedpyclusteringinrun_xmeans(), raisingOptionalDependencyErrorwithextra_name="clustering".src/stride/xai/recurrence/methods.py: Removed unused top-level visualization imports and lazily importedhdbscanincluster_windows(), raisingOptionalDependencyErrorwithextra_name="clustering".src/stride/xai/recurrence/protree/metrics/compare.py: Removed strayicecreamdebug import.src/stride/xai/boundary/ssnp.py&analysis.py: Guarded TensorFlow imports and raisedOptionalDependencyErrorwithextra_name="deeplearning"when TensorFlow is unavailable.src/stride/plotting/stream.py&_renderers.py: Guarded matplotlib imports withfrom __future__ import annotationsand runtime guard checking_HAS_MATPLOTLIB.src/stride/xai/{clustering,importance,stats}/__init__.py: Guarded optional visualization imports withtry/except ImportErrorto support minimal installations withoutmatplotlib/seaborn.src/stride/datasets/protree_data/__init__.py: Guarded click CLI import.3. Automated Verification & Guardrail Tests
tests/test_minimal_install_import.py: Added 10 tests verifying isolated top-level import without optional packages, core model and drift estimator execution on base dependencies, and actionableOptionalDependencyErrortriggers for missing optional packages.Verification
ruff check .passed with 0 errorsruff format --check .passed cleanlypython -m unittest discover testspassed with 0 failures (22 tests executed)mock.patch.dict('sys.modules', {'shap': None, 'lime': None, 'umap': None, 'tensorflow': None, 'pyclustering': None, 'hdbscan': None, 'matplotlib': None, 'seaborn': None}):import stridesucceeded cleanly.