[BUG] fix HRPOpt.optimize raising AttributeError under scipy >= 1.18 - #751
Open
lenamonj wants to merge 1 commit into
Open
[BUG] fix HRPOpt.optimize raising AttributeError under scipy >= 1.18#751lenamonj wants to merge 1 commit into
lenamonj wants to merge 1 commit into
Conversation
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.
Fixes item 3 of #750:
HRPOpt.optimize()validateslinkage_methodagainstscipy.cluster.hierarchy._LINKAGE_METHODS, a private attribute that scipy1.18.0 removed, so every call raises
AttributeError- including the defaultlinkage_method="single"- and CI is red onmain(run 28899115146 ata6638d2).pyproject.tomlallowsscipy>=1.3.0unbounded, so a freshinstall resolves the broken combination.
Fix: delete the pre-check.
scipy.cluster.hierarchy.linkagevalidates themethod itself and raises
ValueError: Invalid method: <name>before touchingdata, so the documented
ValueErrorcontract holds - the existingtest_hrp_errorsassertion passes unchanged - and no private-API dependencyremains.
Test:
test_hrp_linkage_methodsrunsoptimize()over the seven linkagemethods documented by
scipy.cluster.hierarchy.linkageand checks eachreturns a full set of weights summing to 1. scipy exposes no public list of
valid methods, so the test pins the documented seven.
Measured on Python 3.13.8 / scipy 1.18.0 / numpy 2.5.1 / pandas 3.0.5 with
pytest ./tests -q:main: 7 failed, 295 passed, 15 skipped - all seven failures are thisAttributeError(five intest_hrp.py, two intest_plotting.py, both ofwhich construct an
HRPOpt).mainfails with the sameAttributeError.ruff checkandruff formatclean on both changed files.If you would like an upper bound (
scipy>=1.3.0,<2.0.0) so a future scipy2.0 cannot repeat this failure mode, happy to add it here or as a separate
PR, whichever fits your dependency policy.