Skip to content

[Compatibility Issue] np.bool removed in NumPy 1.24 — use bool instead #94

Description

@xyf5432

Affected File

lib/utils/data_utils.py:410-411

Current Code

def inter_from_mask(pred, gt):
    pred = pred.astype(np.bool)
    gt = gt.astype(np.bool)
    intersection = np.logical_and(gt, pred).sum()
    return intersection

Root Cause

np.bool was deprecated in NumPy 1.20 and fully removed in NumPy 1.24 (2022-12). In NumPy >= 1.24, using np.bool raises:

AttributeError: module 'numpy' has no attribute 'bool'

np.bool was an alias for Python's built-in bool.

Impact

  • Severity: High — hard crash at runtime on NumPy >= 1.24
  • Affects the inter_from_mask utility function used for intersection computation between prediction and ground-truth masks

Dependency Chain

Although requirements.txt does not list numpy directly, it is pulled in transitively by every declared dependency:

Package Requires numpy
scikit-image==0.19.0 numpy>=1.24
opencv-python numpy>=2 (Python 3.9+)
kornia numpy<3 (dev extra)
imgaug numpy>=1.15
lpips numpy>=1.14.3
imageio==2.27.0 numpy
plyfile numpy>=2.0
tensorboardX numpy

The resolver takes the tightest constraints: numpy>=2.0 (from plyfile and opencv-python). Any numpy >= 2.0 has already removed np.bool, so this issue is guaranteed to trigger.

Solution

# Before:
pred = pred.astype(np.bool)
gt = gt.astype(np.bool)

# After:
pred = pred.astype(bool)
gt = gt.astype(bool)

Python's built-in bool is the canonical replacement. np.bool_ can also be used if NumPy scalar type is explicitly required.

References

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