Skip to content

Commit 1089bac

Browse files
authored
Merge pull request #242 from numpy/missing-core-stubs
🏷️ stub the missing submodules of `numpy.core`
1 parent d7f4fd1 commit 1089bac

21 files changed

+1610
-37
lines changed

.mypyignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ numpy(\..+)?\.complex(192|256)
1717

1818
# these are always either missing float96/complex192 or float128/complex256
1919
numpy\.__all__
20-
numpy\._core\.__all__
21-
numpy\._core\.numeric\.__all__
22-
numpy\._core\.numerictypes\.__all__
20+
numpy\._?core\.__all__
21+
numpy\._?core\.numeric\.__all__
22+
numpy\._?core\.numerictypes\.__all__
2323
numpy\.matlib\.__all__
2424

2525
# requires numpy/_core/code_generators to be on the PYTHONPATH when running stubtest

.mypyignore-todo

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ numpy(\..+)?\.complexfloating.__complex__
1111
numpy(\.lib\._nanfunctions_impl|\.matlib)?\.nan(median|percentile)
1212
numpy(\.lib\._twodim_base_impl)?\.tri(l|u)
1313

14-
numpy\._core(\._multiarray_umath|\.multiarray)\.error
14+
numpy\._?core(\._multiarray_umath|\.multiarray)\.error
1515
numpy(\._core(\.memmap)?|\.matlib)?\.memmap\.__new__
1616
numpy(\.matrixlib(\.defmatrix)?|\.matlib)?\.matrix\.__new__
1717
numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ
@@ -25,10 +25,10 @@ numpy._core._type_aliases.type_info
2525
numpy._core._type_aliases.k
2626
numpy._core._type_aliases.v
2727

28-
numpy(\._core(\.records)?|\.matlib|\.rec)?\.recarray\.__getattr__
29-
numpy(\._core(\.records)?|\.matlib|\.rec)?\.recarray\.__new__
30-
numpy(\._core(\.records)?|\.matlib|\.rec)?\.record\.__name__
31-
numpy(\._core\.records|\.rec)\.array
28+
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.recarray\.__getattr__
29+
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.recarray\.__new__
30+
numpy(\._?core(\.records)?|\.matlib|\.rec)?\.record\.__name__
31+
numpy(\._?core\.records|\.rec)\.array
3232

3333
numpy._globals._CopyMode.IF_NEEDED
3434
numpy._globals._CopyMode.__bool__
@@ -38,19 +38,6 @@ numpy._pyinstaller.hook-numpy
3838
numpy.compat
3939
numpy.compat.py3k
4040

41-
numpy.core.arrayprint
42-
numpy.core.defchararray
43-
numpy.core.einsumfunc
44-
numpy.core.fromnumeric
45-
numpy.core.function_base
46-
numpy.core.getlimits
47-
numpy.core.multiarray
48-
numpy.core.numeric
49-
numpy.core.numerictypes
50-
numpy.core.records
51-
numpy.core.shape_base
52-
numpy.core.umath
53-
5441
numpy.ctypeslib._ctypeslib
5542

5643
numpy.distutils

src/numpy-stubs/core/__init__.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# TODO(jorenham):
2-
# add mirror modules of `_core` in the `core` namespace
3-
41
from numpy import _core as _core # noqa: ICN003
52
from numpy._core import (
63
_dtype,
@@ -41,9 +38,3 @@ __all__ = [
4138
"shape_base",
4239
"umath",
4340
]
44-
45-
# TODO(jorenham): stub `_core._dtype_ctypes`
46-
# https://github.com/numpy/numtype/issues/54
47-
48-
# TODO(jorenham): stub `_core._dtype`
49-
# https://github.com/numpy/numtype/issues/55

src/numpy-stubs/core/_dtype.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from numpy._core._dtype import (
2+
_aligned_offset as _aligned_offset,
3+
_byte_order_str as _byte_order_str,
4+
_construction_repr as _construction_repr,
5+
_datetime_metadata_str as _datetime_metadata_str,
6+
_is_packed as _is_packed,
7+
_isunsized as _isunsized,
8+
_kind_name as _kind_name,
9+
_kind_to_stem as _kind_to_stem,
10+
_name_get as _name_get,
11+
_name_includes_bit_suffix as _name_includes_bit_suffix,
12+
_scalar_str as _scalar_str,
13+
_struct_dict_str as _struct_dict_str,
14+
_struct_list_str as _struct_list_str,
15+
_struct_str as _struct_str,
16+
_subarray_str as _subarray_str,
17+
_unpack_field as _unpack_field,
18+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from numpy._core._dtype_ctypes import (
2+
_from_ctypes_array as _from_ctypes_array,
3+
_from_ctypes_scalar as _from_ctypes_scalar,
4+
_from_ctypes_structure as _from_ctypes_structure,
5+
_from_ctypes_union as _from_ctypes_union,
6+
dtype_from_ctypes_type as dtype_from_ctypes_type,
7+
)

src/numpy-stubs/core/_internal.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from numpy._core._internal import (
2+
IS_PYPY as IS_PYPY,
3+
_ctypes as _ctypes,
4+
array_function_errmsg_formatter as array_function_errmsg_formatter,
5+
array_ufunc_errmsg_formatter as array_ufunc_errmsg_formatter,
6+
dummy_ctype as dummy_ctype,
7+
format_re as format_re,
8+
npy_ctypes_check as npy_ctypes_check,
9+
sep_re as sep_re,
10+
space_re as space_re,
11+
)
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
from typing import Any
2+
3+
from numpy._core._multiarray_umath import (
4+
ALLOW_THREADS as ALLOW_THREADS,
5+
BUFSIZE as BUFSIZE,
6+
CLIP as CLIP,
7+
DATETIMEUNITS as DATETIMEUNITS,
8+
FLOATING_POINT_SUPPORT as FLOATING_POINT_SUPPORT,
9+
FPE_DIVIDEBYZERO as FPE_DIVIDEBYZERO,
10+
FPE_INVALID as FPE_INVALID,
11+
FPE_OVERFLOW as FPE_OVERFLOW,
12+
FPE_UNDERFLOW as FPE_UNDERFLOW,
13+
ITEM_HASOBJECT as ITEM_HASOBJECT,
14+
ITEM_IS_POINTER as ITEM_IS_POINTER,
15+
LIST_PICKLE as LIST_PICKLE,
16+
MAXDIMS as MAXDIMS,
17+
MAY_SHARE_BOUNDS as MAY_SHARE_BOUNDS,
18+
MAY_SHARE_EXACT as MAY_SHARE_EXACT,
19+
NAN as NAN,
20+
NEEDS_INIT as NEEDS_INIT,
21+
NEEDS_PYAPI as NEEDS_PYAPI,
22+
NINF as NINF,
23+
NZERO as NZERO,
24+
PINF as PINF,
25+
PZERO as PZERO,
26+
RAISE as RAISE,
27+
UFUNC_BUFSIZE_DEFAULT as UFUNC_BUFSIZE_DEFAULT,
28+
UFUNC_PYVALS_NAME as UFUNC_PYVALS_NAME,
29+
USE_GETITEM as USE_GETITEM,
30+
USE_SETITEM as USE_SETITEM,
31+
WRAP as WRAP,
32+
__cpu_baseline__ as __cpu_baseline__,
33+
__cpu_dispatch__ as __cpu_dispatch__,
34+
__cpu_features__ as __cpu_features__,
35+
__cpu_targets_info__ as __cpu_targets_info__,
36+
__version__ as __version__,
37+
_add_newdoc_ufunc as _add_newdoc_ufunc,
38+
_arg as _arg,
39+
_center as _center,
40+
_expandtabs as _expandtabs,
41+
_expandtabs_length as _expandtabs_length,
42+
_extobj_contextvar as _extobj_contextvar,
43+
_flagdict as _flagdict,
44+
_get_extobj_dict as _get_extobj_dict,
45+
_get_madvise_hugepage as _get_madvise_hugepage,
46+
_get_ndarray_c_version as _get_ndarray_c_version,
47+
_ljust as _ljust,
48+
_lstrip_chars as _lstrip_chars,
49+
_lstrip_whitespace as _lstrip_whitespace,
50+
_make_extobj as _make_extobj,
51+
_monotonicity as _monotonicity,
52+
_ones_like as _ones_like,
53+
_partition as _partition,
54+
_partition_index as _partition_index,
55+
_place as _place,
56+
_reconstruct as _reconstruct,
57+
_replace as _replace,
58+
_rjust as _rjust,
59+
_rpartition as _rpartition,
60+
_rpartition_index as _rpartition_index,
61+
_rstrip_chars as _rstrip_chars,
62+
_rstrip_whitespace as _rstrip_whitespace,
63+
_set_madvise_hugepage as _set_madvise_hugepage,
64+
_strip_chars as _strip_chars,
65+
_strip_whitespace as _strip_whitespace,
66+
_vec_string as _vec_string,
67+
_zfill as _zfill,
68+
absolute as absolute,
69+
add as add,
70+
add_docstring as add_docstring,
71+
arange as arange,
72+
arccos as arccos,
73+
arccosh as arccosh,
74+
arcsin as arcsin,
75+
arcsinh as arcsinh,
76+
arctan as arctan,
77+
arctan2 as arctan2,
78+
arctanh as arctanh,
79+
array as array,
80+
asanyarray as asanyarray,
81+
asarray as asarray,
82+
ascontiguousarray as ascontiguousarray,
83+
asfortranarray as asfortranarray,
84+
bincount as bincount,
85+
bitwise_and as bitwise_and,
86+
bitwise_count as bitwise_count,
87+
bitwise_or as bitwise_or,
88+
bitwise_xor as bitwise_xor,
89+
broadcast as broadcast,
90+
busday_count as busday_count,
91+
busday_offset as busday_offset,
92+
busdaycalendar as busdaycalendar,
93+
c_einsum as c_einsum,
94+
can_cast as can_cast,
95+
cbrt as cbrt,
96+
ceil as ceil,
97+
clip as clip,
98+
compare_chararrays as compare_chararrays,
99+
concatenate as concatenate,
100+
conj as conj,
101+
conjugate as conjugate,
102+
copysign as copysign,
103+
copyto as copyto,
104+
correlate as correlate,
105+
correlate2 as correlate2,
106+
cos as cos,
107+
cosh as cosh,
108+
count as count,
109+
count_nonzero as count_nonzero,
110+
datetime_as_string as datetime_as_string,
111+
datetime_data as datetime_data,
112+
deg2rad as deg2rad,
113+
degrees as degrees,
114+
divide as divide,
115+
divmod as divmod,
116+
dot as dot,
117+
dragon4_positional as dragon4_positional,
118+
dragon4_scientific as dragon4_scientific,
119+
e as e,
120+
empty as empty,
121+
empty_like as empty_like,
122+
endswith as endswith,
123+
equal as equal,
124+
error as error,
125+
euler_gamma as euler_gamma,
126+
exp as exp,
127+
exp2 as exp2,
128+
expm1 as expm1,
129+
fabs as fabs,
130+
find as find,
131+
flagsobj as flagsobj,
132+
flatiter as flatiter,
133+
float_power as float_power,
134+
floor as floor,
135+
floor_divide as floor_divide,
136+
fmax as fmax,
137+
fmin as fmin,
138+
fmod as fmod,
139+
format_longfloat as format_longfloat,
140+
frexp as frexp,
141+
from_dlpack as from_dlpack,
142+
frombuffer as frombuffer,
143+
fromfile as fromfile,
144+
fromiter as fromiter,
145+
frompyfunc as frompyfunc,
146+
fromstring as fromstring,
147+
gcd as gcd,
148+
get_handler_name as get_handler_name,
149+
get_handler_version as get_handler_version,
150+
greater as greater,
151+
greater_equal as greater_equal,
152+
heaviside as heaviside,
153+
hypot as hypot,
154+
index as index,
155+
inner as inner,
156+
interp as interp,
157+
interp_complex as interp_complex,
158+
invert as invert,
159+
is_busday as is_busday,
160+
isalnum as isalnum,
161+
isalpha as isalpha,
162+
isdecimal as isdecimal,
163+
isdigit as isdigit,
164+
isfinite as isfinite,
165+
isinf as isinf,
166+
islower as islower,
167+
isnan as isnan,
168+
isnat as isnat,
169+
isnumeric as isnumeric,
170+
isspace as isspace,
171+
istitle as istitle,
172+
isupper as isupper,
173+
lcm as lcm,
174+
ldexp as ldexp,
175+
left_shift as left_shift,
176+
less as less,
177+
less_equal as less_equal,
178+
lexsort as lexsort,
179+
log as log,
180+
log1p as log1p,
181+
log2 as log2,
182+
log10 as log10,
183+
logaddexp as logaddexp,
184+
logaddexp2 as logaddexp2,
185+
logical_and as logical_and,
186+
logical_not as logical_not,
187+
logical_or as logical_or,
188+
logical_xor as logical_xor,
189+
matvec as matvec,
190+
maximum as maximum,
191+
may_share_memory as may_share_memory,
192+
min_scalar_type as min_scalar_type,
193+
minimum as minimum,
194+
mod as mod,
195+
modf as modf,
196+
multiply as multiply,
197+
nditer as nditer,
198+
negative as negative,
199+
nested_iters as nested_iters,
200+
nextafter as nextafter,
201+
not_equal as not_equal,
202+
packbits as packbits,
203+
pi as pi,
204+
positive as positive,
205+
power as power,
206+
promote_types as promote_types,
207+
putmask as putmask,
208+
rad2deg as rad2deg,
209+
radians as radians,
210+
ravel_multi_index as ravel_multi_index,
211+
reciprocal as reciprocal,
212+
remainder as remainder,
213+
result_type as result_type,
214+
rfind as rfind,
215+
right_shift as right_shift,
216+
rindex as rindex,
217+
rint as rint,
218+
scalar as scalar,
219+
set_datetimeparse_function as set_datetimeparse_function,
220+
set_typeDict as set_typeDict,
221+
shares_memory as shares_memory,
222+
sign as sign,
223+
signbit as signbit,
224+
sin as sin,
225+
sinh as sinh,
226+
spacing as spacing,
227+
sqrt as sqrt,
228+
square as square,
229+
startswith as startswith,
230+
str_len as str_len,
231+
subtract as subtract,
232+
tan as tan,
233+
tanh as tanh,
234+
tracemalloc_domain as tracemalloc_domain,
235+
true_divide as true_divide,
236+
trunc as trunc,
237+
typeinfo as typeinfo,
238+
unpackbits as unpackbits,
239+
unravel_index as unravel_index,
240+
vdot as vdot,
241+
vecdot as vecdot,
242+
vecmat as vecmat,
243+
where as where,
244+
zeros as zeros,
245+
)
246+
247+
item: str = ...
248+
attr: Any = ...

src/numpy-stubs/core/_utils.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def _raise_warning(attr: str, submodule: str | None = None) -> None: ...
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from numpy._core.arrayprint import (
2+
array2string,
3+
array_repr,
4+
array_str,
5+
format_float_positional,
6+
format_float_scientific,
7+
get_printoptions,
8+
printoptions,
9+
set_printoptions,
10+
)
11+
12+
__all__ = [
13+
"array2string",
14+
"array_repr",
15+
"array_str",
16+
"format_float_positional",
17+
"format_float_scientific",
18+
"get_printoptions",
19+
"printoptions",
20+
"set_printoptions",
21+
]

0 commit comments

Comments
 (0)