8000 Merge pull request #25080 from mtsokol/numpy-bool · numpy/numpy@94bc564 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94bc564

Browse files
authored
Merge pull request #25080 from mtsokol/numpy-bool
API: Add and redefine `numpy.bool` [Array API]
2 parents 8ac314f + e152569 commit 94bc564

File tree

129 files changed

+1035
-1013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1035
-1013
lines changed

benchmarks/benchmarks/bench_ufunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def time_divide_scalar2_inplace(self, dtype):
423423

424424
class CustomComparison(Benchmark):
425425
params = (np.i EED3 nt8, np.int16, np.int32, np.int64, np.uint8, np.uint16,
426-
np.uint32, np.uint64, np.float32, np.float64, np.bool_)
426+
np.uint32, np.uint64, np.float32, np.float64, np.bool)
427427
param_names = ['dtype']
428428

429429
def setup(self, dtype):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Redefine `numpy.bool` as an alias for `numpy.bool_` (as opposed to the `bool`
2+
it was until NumPy 1.24) for Array API compatibility.

doc/source/reference/arrays.scalars.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ Other types
265265
:members: __init__
266266
:exclude-members: __init__
267267

268+
.. autoclass:: numpy.bool
269+
:members: __init__
270+
:exclude-members: __init__
271+
268272
.. autoclass:: numpy.datetime64
269273
:members: __init__
270274
:exclude-members: __init__

doc/source/user/basics.types.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ confusion with builtin python type names, such as `numpy.bool_`.
3030
- Actual C type
3131
- Description
3232

33-
* - `numpy.bool_`
33+
* - `numpy.bool` or `numpy.bool_`
3434
- N/A
3535
- ``bool`` (defined in ``stdbool.h``)
3636
- Boolean (True or False) stored as a byte.
@@ -152,7 +152,7 @@ aliases are provided (See :ref:`sized-aliases`).
152152
NumPy numerical types are instances of ``dtype`` (data-type) objects, each
153153
having unique characteristics. Once you have imported NumPy using
154154
``>>> import numpy as np``
155-
the dtypes are available as ``np.bool_``, ``np.float32``, etc.
155+
the dtypes are available as ``np.bool``, ``np.float32``, etc.
156156

157157
Advanced types, not listed above, are explored in
158158
section :ref:`structured_arrays`.
@@ -198,7 +198,7 @@ the type itself as a function. For example: ::
198198
array([0, 1, 2], dtype=int8)
199199

200200
Note that, above, we use the *Python* float object as a dtype. NumPy knows
201-
that ``int`` refers to ``np.int_``, ``bool`` means ``np.bool_``,
201+
that ``int`` refers to ``np.int_``, ``bool`` means ``np.bool``,
202202
that ``float`` is ``np.float64`` and ``complex`` is ``np.complex128``.
203203
The other data-types do not have Python equivalents.
204204

numpy/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@
128128
array_str, asanyarray, asarray, ascontiguousarray, asfortranarray,
129129
atleast_1d, atleast_2d, atleast_3d, base_repr, binary_repr,
130130
bitwise_and, bitwise_count, bitwise_not, bitwise_or, bitwise_xor,
131-
block, bool_, broadcast, busday_count, busday_offset, busdaycalendar,
132-
byte, bytes_, can_cast, cbrt, cdouble, ceil, character, choose, clip,
133-
clongdouble, complex128, complex64, complexfloating, compress,
134-
concatenate, conj, conjugate, convolve, copysign, copyto, correlate,
135-
cos, cosh, count_nonzero, cross, csingle, cumprod, cumproduct, cumsum,
136-
datetime64, datetime_as_string, datetime_data, deg2rad, degrees,
137-
diagonal, divide, divmod, dot, double, dtype, e, einsum, einsum_path,
138-
empty, empty_like, equal, errstate, euler_gamma, exp, exp2, expm1,
139-
fabs, finfo, flatiter, flatnonzero, flexible, float16, float32,
140-
float64, float_power, floating, floor, floor_divide, fmax, fmin, fmod,
131+
block, bool, bool_, broadcast, busday_count, busday_offset,
132+
busdaycalendar, byte, bytes_, can_cast, cbrt, cdouble, ceil,
133+
character, choose, clip, clongdouble, complex128, complex64,
134+
complexfloating, compress, concatenate, conj, conjugate, convolve,
135+
copysign, copyto, correlate, cos, cosh, count_nonzero, cross, csingle,
136+
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
137+
datetime_data, deg2rad, degrees, diagonal, divide, divmod, dot,
138+
double, dtype, e, einsum, einsum_path, empty, empty_like, equal,
139+
errstate, euler_gamma, exp, exp2, expm1, fabs, finfo, flatiter,
140+
flatnonzero, flexible, float16, float32, float64, float_power,
141+
floating, floor, floor_divide, fmax, fmin, fmod,
141142
format_float_positional, format_float_scientific, frexp, from_dlpack,
142143
frombuffer, fromfile, fromfunction, fromiter, frompyfunc, fromstring,
143144
full, full_like, gcd, generic, geomspace, get_printoptions,
@@ -266,7 +267,6 @@
266267

267268
_type_info = [
268269
("object", ""), # The NumPy scalar only exists by name.
269-
("bool", _specific_msg.format("bool_")),
270270
("float", _specific_msg.format("float64")),
271271
("complex", _specific_msg.format("complex128")),
272272
("str", _specific_msg.format("str_")),
@@ -283,7 +283,7 @@
283283
# probably wait for NumPy 1.26 or 2.0.
284284
# When defined, these should possibly not be added to `__all__` to avoid
285285
# import with `from numpy import *`.
286-
__future_scalars__ = {"bool", "str", "bytes", "object"}
286+
__future_scalars__ = {"str", "bytes", "object"}
287287

288288
# now that numpy core module is imported, can initialize limits
289289
_core.getlimits._register_known_types()

0 commit comments

Comments
 (0)
0