8000 Completed typing rewrite · numpy/numpy@504b601 · GitHub
[go: up one dir, main page]

Skip to content

Commit 504b601

Browse files
committed
Completed typing rewrite
1 parent 45f8057 commit 504b601

37 files changed

+421
-415
lines changed

numpy/__init__.py

Lines changed: 11 additions & 10 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, 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,

numpy/__init__.pyi

Lines changed: 206 additions & 205 deletions
Large diffs are not rendered by default.

numpy/_core/_add_newdocs_scalars.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,22 @@ def add_newdoc_for_scalar_type(obj, fixed_aliases, doc):
9393
add_newdoc('numpy._core.numerictypes', obj, docstring)
9494

9595

96-
add_newdoc_for_scalar_type('bool_', [],
96+
_bool_docstring = (
9797
"""
9898
Boolean type (True or False), stored as a byte.
9999
100100
.. warning::
101101
102-
The :class:`bool_` type is not a subclass of the :class:`int_` type
103-
(the :class:`bool_` is not even a number type). This is different
102+
The :class:`bool` type is not a subclass of the :class:`int_` type
103+
(the :class:`bool` is not even a number type). This is different
104104
than Python's default implementation of :class:`bool` as a
105105
sub-class of :class:`int`.
106-
""")
106+
"""
107+
)
108+
109+
add_newdoc_for_scalar_type('bool', [], _bool_docstring)
110+
111+
add_newdoc_for_scalar_type('bool_', [], _bool_docstring)
107112

108113
add_newdoc_for_scalar_type('byte', [],
109114
"""

numpy/_core/_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
111111

112112
# Cast bool, unsigned int, and int to float64 by default
113113
if dtype is None:
114-
if issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
114+
if issubclass(arr.dtype.type, (nt.integer, nt.bool)):
115115
dtype = mu.dtype('f8')
116116
elif issubclass(arr.dtype.type, nt.float16):
117117
dtype = mu.dtype('f4')
@@ -145,7 +145,7 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
145145
stacklevel=2)
146146

147147
# Cast bool, unsigned int, and int to float64 by default
148-
if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
148+
if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool)):
149149
dtype = mu.dtype('f8')
150150

151151
if mean is not None:

numpy/_core/arrayprint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
set_legacy_print_mode)
4040
from .fromnumeric import any
4141
from .numeric import concatenate, asarray, errstate
42-
from .numerictypes import (longlong, intc, int_, float64, complex128, bool_,
42+
from .numerictypes import (longlong, intc, int_, float64, complex128,
4343
flexible)
4444
from .overrides import array_function_dispatch, set_module
4545
import operator
@@ -474,7 +474,7 @@ def _get_format_function(data, **options):
474474
formatdict = _get_formatdict(data, **options)
475475
if dtypeobj is None:
476476
return formatdict["numpystr"]()
477-
elif issubclass(dtypeobj, _nt.bool_):
477+
elif issubclass(dtypeobj, _nt.bool):
478478
return formatdict['bool']()
479479
elif issubclass(dtypeobj, _nt.integer):
480480
if issubclass(dtypeobj, _nt.timedelta64):
@@ -1460,7 +1460,7 @@ def _void_scalar_to_string(x, is_repr=True):
14601460
return f"{cls_fqn}({val_repr}, dtype={void_dtype!s})"
14611461

14621462

1463-
_typelessdata = [int_, float64, complex128, bool_]
1463+
_typelessdata = [int_, float64, complex128, _nt.bool]
14641464

14651465

14661466
def dtype_is_implied(dtype):
@@ -1490,7 +1490,7 @@ def dtype_is_implied(dtype):
14901490
array([1, 2, 3], dtype=int8)
14911491
"""
14921492
dtype = np.dtype(dtype)
1493-
if _format_options['legacy'] <= 113 and dtype.type == bool_:
1493+
if _format_options['legacy'] <= 113 and dtype.type == np.bool:
14941494
return False
14951495

14961496
# not just void types can be structured, and names are not part of the repr

numpy/_core/arrayprint.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ from typing import Any, Literal, TypedDict, SupportsIndex
55
# of a `contextlib.context` returning an instance of aforementioned class
66
from contextlib import _GeneratorContextManager
77

8+
import numpy as np
89
from numpy import (
9-
bool_,
1010
integer,
1111
timedelta64,
1212
datetime64,
@@ -21,7 +21,7 @@ from numpy._typing import NDArray, _CharLike_co, _FloatLike_co
2121
_FloatMode = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
2222

2323
class _FormatDict(TypedDict, total=False):
24-
bool: Callable[[bool_], str]
24+
bool: Callable[[np.bool], str]
2525
int: Callable[[integer[Any]], str]
2626
timedelta: Callable[[timedelta64], str]
2727
datetime: Callable[[datetime64], str]

numpy/_core/defchararray.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from .._utils import set_module
2121
from .numerictypes import (
22-
bytes_, str_, integer, int_, object_, bool_, character)
22+
bytes_, str_, integer, int_, object_, character)
2323
from .numeric import ndarray, array as narray
2424
from numpy._core.multiarray import _vec_string, compare_chararrays
2525
from numpy._core import overrides
@@ -832,7 +832,7 @@ def isalnum(a):
832832
--------
833833
str.isalnum
834834
"""
835-
return _vec_string(a, bool_, 'isalnum')
835+
return _vec_string(a, numpy.bool, 'isalnum')
836836

837837

838838
@array_function_dispatch(_unary_op_dispatcher)
@@ -920,7 +920,7 @@ def islower(a):
920920
--------
921921
str.islower
922922
"""
923-
return _vec_string(a, bool_, 'islower')
923+
return _vec_string(a, numpy.bool, 'islower')
924924

925925

926926
@array_function_dispatch(_unary_op_dispatcher)
@@ -973,7 +973,7 @@ def istitle(a):
973973
--------
974974
str.istitle
975975
"""
976-
return _vec_string(a, bool_, 'istitle')
976+
return _vec_string(a, numpy.bool, 'istitle')
977977

978978

979979
@array_function_dispatch(_unary_op_dispatcher)
@@ -1010,7 +1010,7 @@ def isupper(a):
10101010
array([False, T 2851 rue, False])
10111011
10121012
"""
1013-
return _vec_string(a, bool_, 'isupper')
1013+
return _vec_string(a, numpy.bool, 'isupper')
10141014

10151015

10161016
def _join_dispatcher(sep, seq):

0 commit comments

Comments
 (0)
0