Skip to content

fix: validate SA3 extraction mode early#516

Closed
samay2504 wants to merge 1 commit intopysal:mainfrom
samay2504:fix/sa3-invalid-extraction
Closed

fix: validate SA3 extraction mode early#516
samay2504 wants to merge 1 commit intopysal:mainfrom
samay2504:fix/sa3-invalid-extraction

Conversation

@samay2504
Copy link
Copy Markdown

This PR fixes the SA3 extraction error path by validating the extraction mode before importing optional clustering dependencies, so unsupported values now raise the expected ValueError immediately instead of being masked by an ImportError when fast_hdbscan is unavailable; this keeps user-facing errors accurate and aligns runtime behaviour with the existing test expectation.

Copilot AI review requested due to automatic review settings April 11, 2026 16:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes SA3 cluster extraction error handling by validating the extraction mode before importing optional fast_hdbscan dependencies, ensuring invalid modes raise the intended ValueError instead of being masked by an ImportError.

Changes:

  • Added early validation for extraction values ("eom" / "leaf") in extract_clusters.
  • Removed the now-unreachable fallback else branch for invalid extraction after extraction selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.9%. Comparing base (9b36063) to head (e9322c4).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #516   +/-   ##
=====================================
  Coverage   76.9%   76.9%           
=====================================
  Files         29      29           
  Lines       3700    3701    +1     
=====================================
+ Hits        2846    2847    +1     
  Misses       854     854           
Files with missing lines Coverage Δ
spopt/region/sa3.py 92.3% <100.0%> (+0.1%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martinfleis
Copy link
Copy Markdown
Member

How does it matter which error bubbles up first? You need both - correct method and dependency.

@samay2504
Copy link
Copy Markdown
Author

Good point, thanks. The reason I changed the order is that extraction validation is independent of optional deps, so a typo in extraction currently surfaces as a dependency error and can send users in the wrong direction. My intent was to fail fast on invalid user input first, then only check optional deps for valid extraction paths. That said, I can absolutely switch this if you prefer dependency-first error bubbling here. Happy to update to your preferred behaviour.

@martinfleis
Copy link
Copy Markdown
Member

It simply does not matter. If you make a typo, fixing it does not help you if you don't have the dependencies. And there's no path in SA3 that would avoid using them.

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.

3 participants