Skip to content

[ENH] Added catch all exceptions block instead of just catching ImportError & AttributeError in _safe_import#494

Merged
fkiraly merged 5 commits intosktime:mainfrom
RecreationalMath:safeImport
Feb 25, 2026
Merged

[ENH] Added catch all exceptions block instead of just catching ImportError & AttributeError in _safe_import#494
fkiraly merged 5 commits intosktime:mainfrom
RecreationalMath:safeImport

Conversation

@RecreationalMath
Copy link
Member

@RecreationalMath RecreationalMath commented Feb 20, 2026

Reference Issues/PRs

Fixes #493 by moving functionality from sktime to skbase.

What does this implement/fix? Explain your changes.

I have added a catch-all exception block in _safe_import instead of the current exception block, which only catches ImportError & AttributeError.

This change makes _safe_import exhibit more aggressive error catching and addresses the problem of occasional breakage due to unsafe cascading imports, e.g., if a new version of a soft dependency has a breaking import.
As suggested in this comment

Does your contribution introduce a new dependency? If yes, which one?

No

Did you add any tests for the change?

Yes, added test_safe_import_catches_non_import_error in skbase/utils/dependencies/tests/test_safe_import.py to check the flow of catch-all exception block.

PR checklist

For all contributions
  • I've reviewed the project documentation on contributing
  • I've added myself to the list of contributors.
  • The PR title starts with either [ENH], [CI/CD], [MNT], [DOC], or [BUG] indicating whether
    the PR topic is related to enhancement, CI/CD, maintenance, documentation, or a bug.
For code contributions
  • Unit tests have been added covering code functionality
  • Appropriate docstrings have been added (see documentation standards)
  • _safe_import is a private function, no action required. New public functionality has been added to the APIReference

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.45%. Comparing base (306958d) to head (68410fe).
⚠️ Report is 179 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
- Coverage   85.07%   83.45%   -1.62%     
==========================================
  Files          45       52       +7     
  Lines        3015     3905     +890     
==========================================
+ Hits         2565     3259     +694     
- Misses        450      646     +196     

☔ 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.

@RecreationalMath RecreationalMath changed the title Added catch all exceptions block instead of just catching ImportError & AttributeError [ENH] Added catch all exceptions block instead of just catching ImportError & AttributeError Feb 20, 2026
@RecreationalMath RecreationalMath changed the title [ENH] Added catch all exceptions block instead of just catching ImportError & AttributeError [ENH] Added catch all exceptions block instead of just catching ImportError & AttributeError in _safe_import Feb 20, 2026
@fkiraly fkiraly merged commit 93eeff0 into sktime:main Feb 25, 2026
23 checks passed
@fkiraly fkiraly added the enhancement Adding new functionality label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adding new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] _safe_import should catch all exceptions, not just ImportError & AttributeError

2 participants