Skip to content

Fix NumPy 2.0 compatibility: Replace deprecated np.asfarray with np.asarray #230

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 6, 2025

This PR fixes a NumPy 2.0 compatibility issue in the AMSS lectures where np.asfarray was removed in NumPy 2.0.

Problem

The code in lectures/_static/lecture_specific/amss2/recursive_allocation.py uses np.asfarray() which was deprecated and removed in NumPy 2.0. This causes the following error when running the amss2 and amss3 lectures with NumPy 2.0+:

AttributeError: `np.asfarray` was removed in the NumPy 2.0 release. Use `np.asarray` with a proper dtype instead.

Both amss2 and amss3 lectures are affected since they use the same RecursiveAllocationAMSS class.

Solution

Replaced the deprecated np.asfarray(x) with the functionally equivalent np.asarray(x, dtype=float) on line 233 of the recursive_allocation.py file.

Before:

x0 = np.asfarray(x)

After:

x0 = np.asarray(x, dtype=float)

Testing

  • ✅ Verified both methods produce identical results with NumPy 1.26.4
  • ✅ Confirmed compatibility with NumPy 2.0+ (simulated environment)
  • ✅ Tested the specific numerical gradient computation pattern
  • ✅ Verified file compiles without errors
  • ✅ Confirmed no other instances of np.asfarray exist in the codebase

This is a minimal, surgical fix that maintains exact functional equivalence while ensuring forward compatibility with NumPy 2.0+.

Fixes #224.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

netlify bot commented Aug 6, 2025

Deploy Preview for lustrous-melomakarona-3ee73e ready!

Name Link
🔨 Latest commit c2749ab
🔍 Latest deploy log https://app.netlify.com/projects/lustrous-melomakarona-3ee73e/deploys/6892b7cc29a73f0008d1d103
😎 Deploy Preview https://deploy-preview-230--lustrous-melomakarona-3ee73e.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mmcky mmcky added the testing label Aug 6, 2025
Copy link

github-actions bot commented Aug 6, 2025

@Copilot Copilot AI changed the title [WIP] [amss2, amss3] lecture needs to be updated for compat with numpy>=2 Fix NumPy 2.0 compatibility: Replace deprecated np.asfarray with np.asarray Aug 6, 2025
@Copilot Copilot AI requested a review from mmcky August 6, 2025 02:04
Copilot finished work on behalf of mmcky August 6, 2025 02:04
@github-actions github-actions bot temporarily deployed to pull request August 6, 2025 02:24 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 6, 2025 02:24 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[amss2, amss3] lecture needs to be updated for compat with numpy>=2
2 participants