Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dtype warning in HRPOpt: cast weights to float before multiplication #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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