Skip to content

HRPOpt fails with current SciPy because _LINKAGE_METHODS was removed #754

Description

@Samarthuday
## Description

`HRPOpt.optimize()` fails with current SciPy versions because it accesses the private attribute `scipy.cluster.hierarchy._LINKAGE_METHODS`.

## Environment

- PyPortfolioOpt: 1.6.0
- Python: 3.14.6
- SciPy: 1.18.0
- macOS arm64

## Reproduction

```python
import pandas as pd
from pypfopt import HRPOpt

prices = pd.DataFrame(
    {
        "A": [100, 101, 99, 102, 103],
        "B": [100, 98, 101, 100, 104],
        "C": [100, 102, 103, 101, 105],
        "D": [100, 99, 100, 103, 102],
    }
)

returns = prices.pct_change().dropna()

hrp = HRPOpt(returns)
hrp.optimize()

Expected behavior

HRPOpt.optimize() should return portfolio weights for valid linkage methods.

Actual behavior

The call raises:

AttributeError:
module 'scipy.cluster.hierarchy' has no attribute '_LINKAGE_METHODS'

The error occurs during linkage-method validation before the portfolio is optimized.

Impact

HRP optimization fails with current SciPy versions, causing HRP-related tests to fail.

Pull request intention

I would like to submit a pull request that replaces this private SciPy API usage with a compatible validation approach and adds regression tests for the supported linkage methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions