Skip to content

Numpy deprecation of numpy.bool in 1.20 #39

@Cordelya

Description

@Cordelya

tl;dr: numpy.bool_ is the new numpy.bool, or as the Numpy 1.20 Deprecation log says, "Just use bool"

I found a thing that will want updating in the future, as I'm running through the v2 tutorial using Python 3.11 and numpy 1.24.2.
Once I get through the entire tutorial and assuming that my changes still work (and as long as I have available time and focus), I can submit a PR. At minimum, that could simply consist of including a note in the text about the difference between what numpy < 1.20 expects and what numpy >= 1.20 expects.

First seen in Part 2, in the file tile_types.py:

# Tile struct used for statically defined tile data.
tile_dt = np.dtype(
    [
        ("walkable", np.bool),  # True if this tile can be walked over.
        ("transparent", np.bool),  # True if this tile doesn't block FOV.
        ("dark", graphic_dt),  # Graphics for when this tile is not in FOV.
    ]
)

Using np.bool here (again, with Python 3.11 & numpy 1.24.2) throws an error:

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'bool_'?

I tested replacing both instances of np.bool with np.bool_ and also bool in my code and there's no longer any yelling either way.

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