Skip to content

Commit

Permalink
Use np.bool_ instead of np.bool8, which is deprecated (python-gra…
Browse files Browse the repository at this point in the history
…phblas#349)

NumPy 1.24 deprecates `np.bool8`, which is an alias of `np.bool_`:
https://numpy.org/devdocs/release/1.24.0-notes.html#np-str0-and-similar-are-now-deprecated
  • Loading branch information
eriknw authored Dec 20, 2022
1 parent f8827cd commit 70a0d17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions graphblas/core/ss/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,13 @@ def export(self, format=None, *, sort=False, give_ownership=False, raw=False):
- The number of cols present in the data structure
- "bitmapr" format
- ``raw=False``
- bitmap : ndarray(dtype=bool8, ndim=2, shape=(nrows, ncols), order="C")
- bitmap : ndarray(dtype=bool, ndim=2, shape=(nrows, ncols), order="C")
- values : ndarray(ndim=2, shape=(nrows, ncols), order="C")
- Elements where bitmap is False are undefined
- nvals : int
- The number of True elements in the bitmap
- ``raw=True``
- bitmap : ndarray(dtype=bool8, ndim=1, size=nrows * ncols)
- bitmap : ndarray(dtype=bool, ndim=1, size=nrows * ncols)
- Stored row-oriented
- values : ndarray(ndim=1, size=nrows * ncols)
- Elements where bitmap is False are undefined
Expand All @@ -639,13 +639,13 @@ def export(self, format=None, *, sort=False, give_ownership=False, raw=False):
- ncols : int
- "bitmapc" format
- ``raw=False``
- bitmap : ndarray(dtype=bool8, ndim=2, shape=(nrows, ncols), order="F")
- bitmap : ndarray(dtype=bool, ndim=2, shape=(nrows, ncols), order="F")
- values : ndarray(ndim=2, shape=(nrows, ncols), order="F")
- Elements where bitmap is False are undefined
- nvals : int
- The number of True elements in the bitmap
- ``raw=True``
- bitmap : ndarray(dtype=bool8, ndim=1, size=nrows * ncols)
- bitmap : ndarray(dtype=bool, ndim=1, size=nrows * ncols)
- Stored column-oriented
- values : ndarray(ndim=1, size=nrows * ncols)
- Elements where bitmap is False are undefined
Expand Down Expand Up @@ -1065,7 +1065,7 @@ def _export(self, format=None, *, sort=False, give_ownership=False, raw=False, m
parent,
)
is_iso = is_iso[0]
bool_dtype = np.dtype(np.bool8)
bool_dtype = np.dtype(np.bool_)
if raw:
bitmap = claim_buffer(ffi, Ab[0], Ab_size[0] // bool_dtype.itemsize, bool_dtype)
values = claim_buffer(ffi, Ax[0], Ax_size[0] // dtype.itemsize, dtype)
Expand Down Expand Up @@ -1943,7 +1943,7 @@ def import_bitmapr(
to GraphBLAS if possible. To give ownership of the underlying
memory buffers to GraphBLAS, the arrays must:
- be C contiguous
- have the correct dtype (bool8 for bitmap)
- have the correct dtype (bool for bitmap)
- own its own data
- be writeable
If all of these conditions are not met, then the data will be
Expand Down Expand Up @@ -2028,7 +2028,7 @@ def _import_bitmapr(
raise ValueError(f"Invalid format: {format!r} Must be None or 'bitmapr'.")
copy = not take_ownership
bitmap = ints_to_numpy_buffer(
bitmap, np.bool8, copy=copy, ownable=True, order="C", name="bitmap"
bitmap, np.bool_, copy=copy, ownable=True, order="C", name="bitmap"
)
if method == "pack":
dtype = matrix.dtype
Expand Down Expand Up @@ -2119,7 +2119,7 @@ def import_bitmapc(
to GraphBLAS if possible. To give ownership of the underlying
memory buffers to GraphBLAS, the arrays must:
- be FORTRAN contiguous
- have the correct dtype (bool8 for bitmap)
- have the correct dtype (bool for bitmap)
- own its own data
- be writeable
If all of these conditions are not met, then the data will be
Expand Down Expand Up @@ -2204,7 +2204,7 @@ def _import_bitmapc(
raise ValueError(f"Invalid format: {format!r} Must be None or 'bitmapc'.")
copy = not take_ownership
bitmap = ints_to_numpy_buffer(
bitmap, np.bool8, copy=copy, ownable=True, order="F", name="bitmap"
bitmap, np.bool_, copy=copy, ownable=True, order="F", name="bitmap"
)
if method == "pack":
dtype = matrix.dtype
Expand Down
10 changes: 5 additions & 5 deletions graphblas/core/ss/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def export(self, format=None, *, sort=False, give_ownership=False, raw=False):
- size : int
- nvals : int, only present if raw == True
- "bitmap" format
- bitmap : ndarray(dtype=bool8, size=size)
- bitmap : ndarray(dtype=bool, size=size)
- values : ndarray(size=size)
- Elements where bitmap is False are undefined
- nvals : int
Expand Down Expand Up @@ -565,7 +565,7 @@ def _export(self, format=None, *, sort=False, give_ownership=False, raw=False, m
parent,
)
is_iso = is_iso[0]
bool_dtype = np.dtype(np.bool8)
bool_dtype = np.dtype(np.bool_)
bitmap = claim_buffer(ffi, vb[0], vb_size[0] // bool_dtype.itemsize, bool_dtype)
values = claim_buffer(ffi, vx[0], vx_size[0] // dtype.itemsize, dtype)
if not raw:
Expand Down Expand Up @@ -999,7 +999,7 @@ def import_bitmap(
to GraphBLAS if possible. To give ownership of the underlying
memory buffers to GraphBLAS, the arrays must:
- be C contiguous
- have the correct dtype (bool8 for bitmap)
- have the correct dtype (bool for bitmap)
- own its own data
- be writeable
If all of these conditions are not met, then the data will be
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def _import_bitmap(
if format is not None and format.lower() != "bitmap":
raise ValueError(f"Invalid format: {format!r}. Must be None or 'bitmap'.")
copy = not take_ownership
bitmap = ints_to_numpy_buffer(bitmap, np.bool8, copy=copy, ownable=True, name="bitmap")
bitmap = ints_to_numpy_buffer(bitmap, np.bool_, copy=copy, ownable=True, name="bitmap")
if method == "pack":
dtype = vector.dtype
size = vector._size
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def import_full(
to GraphBLAS if possible. To give ownership of the underlying
memory buffers to GraphBLAS, the arrays must:
- be C contiguous
- have the correct dtype (bool8 for bitmap)
- have the correct dtype (bool for bitmap)
- own its own data
- be writeable
If all of these conditions are not met, then the data will be
Expand Down
2 changes: 1 addition & 1 deletion graphblas/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def ints_to_numpy_buffer(array, dtype, *, name="array", copy=False, ownable=Fals
if (
isinstance(array, np.ndarray)
and not np.issubdtype(array.dtype, np.integer)
and not np.issubdtype(array.dtype, np.bool8)
and not np.issubdtype(array.dtype, np.bool_)
):
raise ValueError(f"{name} must be integers, not {array.dtype.name}")
array = np.array(array, dtype, copy=copy, order=order)
Expand Down

0 comments on commit 70a0d17

Please sign in to comment.