Skip to content

Commit e43de40

Browse files
authored
Merge pull request numpy#26210 from mtsokol/bool_-typing
API: Readd `np.bool_` typing stub
2 parents e59c074 + 0d7b977 commit e43de40

File tree

8 files changed

+16
-11
lines changed

8 files changed

+16
-11
lines changed

numpy/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,6 +2817,8 @@ class bool(generic):
28172817
__gt__: _ComparisonOp[_NumberLike_co, _ArrayLikeNumber_co]
28182818
__ge__: _ComparisonOp[_NumberLike_co, _ArrayLikeNumber_co]
28192819

2820+
bool_ = bool
2821+
28202822
class object_(generic):
28212823
def __init__(self, value: object = ..., /) -> None: ...
28222824
@property

numpy/_core/tests/_natype.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def method(self, other):
1515
if (
1616
other is pd_NA
1717
or isinstance(other, (str, bytes))
18-
or isinstance(other, (numbers.Number, np.bool_))
18+
or isinstance(other, (numbers.Number, np.bool))
1919
or util.is_array(other)
2020
and not other.shape
2121
):
@@ -119,7 +119,7 @@ def __reduce__(self):
119119
def __pow__(self, other):
120120
if other is pd_NA:
121121
return pd_NA
122-
elif isinstance(other, (numbers.Number, np.bool_)):
122+
elif isinstance(other, (numbers.Number, np.bool)):
123123
if other == 0:
124124
# returning positive is correct for +/- 0.
125125
return type(other)(1)
@@ -133,7 +133,7 @@ def __pow__(self, other):
133133
def __rpow__(self, other):
134134
if other is pd_NA:
135135
return pd_NA
136-
elif isinstance(other, (numbers.Number, np.bool_)):
136+
elif isinstance(other, (numbers.Number, np.bool)):
137137
if other == 1:
138138
return other
139139
else:
@@ -170,7 +170,7 @@ def __xor__(self, other):
170170
__rxor__ = __xor__
171171

172172
__array_priority__ = 1000
173-
_HANDLED_TYPES = (np.ndarray, numbers.Number, str, np.bool_)
173+
_HANDLED_TYPES = (np.ndarray, numbers.Number, str, np.bool)
174174

175175
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
176176
types = self._HANDLED_TYPES + (NAType,)

numpy/_core/tests/test_multiarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,8 +1890,8 @@ def test_any_where(self):
18901890
["i8", "U10", "object", "datetime64[ms]"])
18911891
def test_any_and_all_result_dtype(self, dtype):
18921892
arr = np.ones(3, dtype=dtype)
1893-
assert arr.any().dtype == np.bool_
1894-
assert arr.all().dtype == np.bool_
1893+
assert arr.any().dtype == np.bool
1894+
assert arr.all().dtype == np.bool
18951895

18961896
def test_any_and_all_object_dtype(self):
18971897
# (seberg) Not sure we should even allow dtype here, but it is.

numpy/_core/tests/test_stringdtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def test_isnan(dtype, string_list):
356356
# isnan is only true when na_object is a NaN
357357
assert_array_equal(
358358
np.isnan(sarr),
359-
np.array([0] * len(string_list) + [1], dtype=np.bool_),
359+
np.array([0] * len(string_list) + [1], dtype=np.bool),
360360
)
361361
else:
362362
assert not np.any(np.isnan(sarr))

numpy/lib/tests/test_function_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ def test_nd(self):
254254
@pytest.mark.parametrize("dtype", ["i8", "U10", "object", "datetime64[ms]"])
255255
def test_any_and_all_result_dtype(dtype):
256256
arr = np.ones(3, dtype=dtype)
257-
assert np.any(arr).dtype == np.bool_
258-
assert np.all(arr).dtype == np.bool_
257+
assert np.any(arr).dtype == np.bool
258+
assert np.all(arr).dtype == np.bool
259259

260260

261261
class TestCopy:

numpy/typing/tests/data/pass/scalars.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66

77
b = np.bool()
8+
b_ = np.bool_()
89
u8 = np.uint64()
910
i8 = np.int64()
1011
f8 = np.float64()
@@ -121,7 +122,7 @@ def __float__(self) -> float:
121122
u8 = np.uint64()
122123
f8 = np.float64()
123124
c16 = np.complex128()
124-
b_ = np.bool()
125+
b = np.bool()
125126
td = np.timedelta64()
126127
U = np.str_("1")
127128
S = np.bytes_("1")
@@ -130,7 +131,7 @@ def __float__(self) -> float:
130131
int(i8)
131132
int(u8)
132133
int(f8)
133-
int(b_)
134+
int(b)
134135
int(td)
135136
int(U)
136137
int(S)

numpy/typing/tests/data/reveal/numerictypes.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ assert_type(np.ScalarType[0], type[int])
4848
assert_type(np.ScalarType[3], type[bool])
4949
assert_type(np.ScalarType[8], type[np.csingle])
5050
assert_type(np.ScalarType[10], type[np.clongdouble])
51+
assert_type(np.bool_, type[np.bool])
5152

5253
assert_type(np.typecodes["Character"], Literal["c"])
5354
assert_type(np.typecodes["Complex"], Literal["FDG"])

numpy/typing/tests/data/reveal/scalars.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ assert_type(V[["field1", "field2"]], np.void)
5050
V[0] = 5
5151

5252
# Aliases
53+
assert_type(np.bool_(), np.bool)
5354
assert_type(np.byte(), np.byte)
5455
assert_type(np.short(), np.short)
5556
assert_type(np.intc(), np.intc)

0 commit comments

Comments
 (0)