fix HRPOpt.optimize() crash on scipy >= 1.18 (removed _LINKAGE_METHODS) - #760
fix HRPOpt.optimize() crash on scipy >= 1.18 (removed _LINKAGE_METHODS)#760kpj2006 wants to merge 1 commit into
Conversation
…t; remove unused linkage_method check in HRPOpt
There was a problem hiding this comment.
@robertmartin8 @fkiraly @tschm is this correct way to do so ?
| if linkage_method not in sch._LINKAGE_METHODS: | ||
| raise ValueError("linkage_method must be one recognised by scipy") | ||
|
|
There was a problem hiding this comment.
remove the precheck entirely. scipy.cluster.hierarchy.linkage() already validates method internally (confirmed by reading scipy's current source: if method not in _LINKAGE_METHODS: raise ValueError(f"Invalid method: {method}"), that dict just isn't exposed as a module attribute anymore. Letting linkage() do its own validation means this doesn't re-break on a future scipy internal refactor.
| numpy>=1.26.0,<3.0.0 | ||
| pandas>=1.0.0,<4.0.0 |
There was a problem hiding this comment.
Also synced requirements.txt's numpy/pandas bounds to match pyproject.toml (numpy>=1.0.0/pandas>=0.19 → numpy>=1.26.0,<3.0.0/pandas>=1.0.0,<4.0.0), found while checking dependency consistency, pip install -r requirements.txt was pulling much older, unsupported versions than the package actually requires.
HRPOpt.optimize() calls sch._LINKAGE_METHODS to validate linkage_method before clustering. That private dict was removed from scipy.cluster.hierarchy's public surface in scipy 1.18's module → package refactor, so on a fresh install with scipy >= 1.18, HRPOpt.optimize() raises AttributeError before it can do anything — the feature is unreachable. This has been failing main's CI (nosoftdeps on Python 3.12/3.13/3.14) since 2026-07-07, and it also breaks cookbook/5-Hierarchical-Risk-Parity.ipynb, which uses HRPOpt.