Skip to content

Conversation

Pranav-20186017
Copy link

Description

This addresses a Future Warning in pypfopt/hierarchical_portfolio.py caused by multiplying integer-type weights with float values. Due to stricter type enforcement, this would cause errors in future pandas versions.

Files Changed

  • pypfopt/hierarchical_portfolio.py

Fix

Explicitly cast weights array to float64 before arithmetic operations:

# Before
w[first_cluster] *= alpha  # weight 1

# After
w = w.astype('float64')  # ensure the weights array is float64
w[first_cluster] *= alpha  # weight 1

Testing Performed

  • Ran full test suite with pytest (no failures)
  • Manually verified warning elimination
  • Confirmed HRP optimization consistency

Checklist

  • Code follows project style guidelines
  • Documentation updated (if applicable)
  • Unit tests pass
  • No unintended side effects

This patch ensures floating-point arithmetic and prevents future dtype conflicts in pandas.

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.

1 participant