Skip to content

np.char.chararray constructor deprecated in numpy >= 2.5.0 #1210

Description

@xyf5432

Affected File

python/Graphs/multi_heuristic_astar.py:82

Current Code

def do_something(back_pointer, goal, start):
    grid = np.char.chararray((n, n))
    for i in range(n):
        for j in range(n):
            grid[i][j] = "*"
    ...

Root Cause

numpy.char.chararray was deprecated in numpy 2.5.0 (numpy/numpy#30605). Constructing a chararray via np.char.chararray((n, n)) now emits:

DeprecationWarning: The chararray class is deprecated

The constructor is called each time do_something runs, which means the warning fires repeatedly during the search algorithm's execution.

Impact

  • Severity: Medium — every call to do_something produces a DeprecationWarning on stderr, accumulating noise as the pathfinding algorithm iterates

Solution

Use a regular numpy array with a string dtype instead:

# Before:
grid = np.char.chararray((n, n))

# After:
grid = np.full((n, n), "*", dtype="<U1")

References


Thank you for taking a look! We would appreciate a confirmation on whether this is a real compatibility issue. Hope it's worth fixing in a future release.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions