10000 API: Add next batch of changes [skip ci] · numpy/numpy@64a4f4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 64a4f4c

Browse files
committed
API: Add next batch of changes [skip ci]
1 parent 09dad16 commit 64a4f4c

15 files changed

+78
-82
lines changed

numpy/__init__.py

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,10 @@
116116
its source directory; please exit the numpy source tree, and relaunch
117117
your python interpreter from there."""
118118
raise ImportError(msg) from e
119-
120-
__all__ = ['exceptions']
121119

122120
from . import core
123121
from .core import (
124-
_no_nep50_warning, memmap,
125-
iinfo, finfo, # getlimits submodule exports
122+
_no_nep50_warning, memmap, Inf, Infinity, NaN, iinfo, finfo,
126123
False_, ScalarType, True_, abs, absolute, add, all, allclose, alltrue,
127124
amax, amin, any, arange, arccos, arccosh, arcsin, arcsinh, arctan,
128125
arctan2, arctanh, argmax, argmin, argpartition, argsort, argwhere,
@@ -139,15 +136,15 @@
139136
datetime_data, deg2rad, degrees, diagonal, divide, divmod, dot,
140137
double, dtype, e, einsum, einsum_path, empty, empty_like, equal,
141138
errstate, euler_gamma, exp, exp2, expm1, fabs, find_common_type,
142-
flatiter, flatnonzero, flexible, float128, float16, float32, float64,
139+
flatiter, flatnonzero, flexible,
143140
float_, float_power, floating, floor, floor_divide, fmax, fmin, fmod,
144141
format_float_positional, format_float_scientific, format_parser,
145142
frexp, from_dlpack, frombuffer, fromfile, fromfunction, fromiter,
146143
frompyfunc, fromstring, full, full_like, gcd, generic, geomspace,
147144
get_printoptions, getbufsize, geterr, geterrcall, greater,
148145
greater_equal, half, heaviside, hstack, hypot, identity, iinfo,
149-
indices, inexact, inf, infty, inner, int16, int32, int64, int8, int_,
150-
intc, integer, intp, invert, is_busday, isclose, isfinite, isfortran,
146+
indices, inexact, inf, infty, inner, int_,
147+
intc, integer, invert, is_busday, isclose, isfinite, isfortran,
151148
isinf, isnan, isnat, isscalar, issctype, issubdtype, lcm, ldexp,
152149
left_shift, less, less_equal, lexsort, linspace, little_endian, log,
153150
log10, log1p, log2, logaddexp, logaddexp2, logical_and, logical_not,
@@ -167,13 +164,23 @@
167164
singlecomplex, sinh, size, sometrue, sort, spacing, sqrt, square,
168165
squeeze, stack, std, str_, string_, subtract, sum, swapaxes, take,
169166
tan, tanh, tensordot, test, timedelta64, trace, transpose,
170-
true_divide, trunc, typecodes, ubyte, ufunc, uint, uint16, uint32,
171-
uint64, uint8, uintc, uintp, ulonglong, unicode_, unsignedinteger,
172-
ushort, var, vdot, void, vstack, warnings, where, zeros, zeros_like
167+
true_divide, trunc, typecodes, ubyte, ufunc, uint, uintc, ulonglong,
168+
unicode_, unsignedinteger, ushort, var, vdot, void, vstack, where,
169+
zeros, zeros_like, _get_promotion_state, _set_promotion_state
173170
)
174171

175-
from . import exceptions
176-
from . import dtypes
172+
sized_aliases = ["int8", "int16", "int32", "int64", "intp",
173+
"uint8", "uint16", "uint32", "uint64", "uintp",
174+
"float16", "float32", "float64", "float96", "float128",
175+
"complex64", "complex128", "complex192", "complex256"]
176+
177+
for sa in sized_aliases:
178+
try:
179+
globals()[sa] = getattr(core, sa)
180+
except AttributeError:
181+
pass
182+
del sa, sized_aliases
183+
177184
from . import lib
178185
# NOTE: to be revisited following future namespace cleanup.
179186
# See gh-14454 and gh-15672 for discussion.
@@ -200,17 +207,12 @@
200207
put_along_axis, quantile, r_, ravel_multi_index, real, real_if_close,
201208
roots, rot90, row_stack, s_, save, savetxt, savez, savez_compressed,
202209
select, setdiff1d, setxor1d, show_runtime, sinc, sort_complex, split,
203-
take_along_axis, test, tile, tracemalloc_domain, trapz, tri, tril,
210+
take_along_axis, tile, tracemalloc_domain, trapz, tri, tril,
204211
tril_indices, tril_indices_from, typename, union1d, unique, unpackbits,
205-
unravel_index, unwrap, vander, vectorize, vsplit
212+
unravel_index, unwrap, vander, vectorize, vsplit, trim_zeros,
213+
triu, triu_indices, triu_indices_from, isposinf, RankWarning, disp,
214+
deprecate, deprecate_with_doc, who, safe_eval, recfromtxt, recfromcsv
206215
)
207-
208-
from . import linalg
209-
from . import fft
210-
from . import polynomial
211-
from . import random
212-
from . import ctypeslib
213-
from . import ma
214216
from . import matrixlib as _mat
215217
from .matrixlib import (
216218
asmatrix, bmat, defmatrix, mat, matrix, test
@@ -259,30 +261,13 @@
259261
# now that numpy core module is imported, can initialize limits
260262
core.getlimits._register_known_types()
261263

264+
__all__ = ['exceptions']
262265
__all__.extend(['__version__', 'show_config'])
263266
__all__.extend(core.__all__)
264267
__all__.extend(_mat.__all__)
265268
__all__.extend(lib.__all__)
266269
__all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])
267270

268-
# Remove one of the two occurrences of `issubdtype`, which is exposed as
269-
# both `numpy.core.issubdtype` and `numpy.lib.issubdtype`.
270-
__all__.remove('issubdtype')
271-
272-
# These are exported by np.core, but are replaced by the builtins below
273-
# remove them to ensure that we don't end up with `np.long == np.int_`,
274-
# which would be a breaking change.
275-
__all__.remove('long')
276-
__all__.remove('unicode')
277-
278-
# Remove things that are in the numpy.lib but not in the numpy namespace
279-
# Note that there is a test under path:
280-
# `numpy/tests/test_public_api.py:test_numpy_namespace`
281-
# that prevents adding more things to the main namespace by accident.
282-
# The list below will grow until the `from .lib import *` fixme above is
283-
# taken care of
284-
__all__.remove('Arrayterator')
285-
286271
# Filter out Cython harmless warnings
287272
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
288273
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
@@ -292,6 +277,37 @@ def __getattr__(attr):
292277
# Warn for expired attributes
293278
import warnings
294279

280+
if attr == "linalg":
281+
import numpy.linalg as linalg
282+
return linalg
283+
elif attr == "fft":
284+
import numpy.fft as fft
285+
return fft
286+
elif attr == "dtypes":
287+
import numpy.dtypes as dtypes
288+
return dtypes
289+
elif attr == "random":
290+
import numpy.random as random
291+
return random
292+
elif attr == "polynomial":
293+
import numpy.polynomial as polynomial
294+
return polynomial
295+
elif attr == "ma":
296+
import numpy.ma as ma
297+
return ma
298+
elif attr == "ctypeslib":
299+
import numpy.ctypeslib as ctypeslib
300+
return ctypeslib
301+
elif attr == "exceptions":
302+
import numpy.exceptions as exceptions
303+
return exceptions
304+
elif attr == 'testing':
305+
import numpy.testing as testing
306+
return testing
307+
elif attr == "matlib":
308+
import numpy.matlib as matlib
309+
return matlib
310+
295311
if attr in __future_scalars__:
296312
# And future warnings for those that will change, but also give
297313
# the AttributeError
@@ -302,10 +318,6 @@ def __getattr__(attr):
302318
if attr in __former_attrs__:
303319
raise AttributeError(__former_attrs__[attr])
304320

305-
if attr == 'testing':
306-
import numpy.testing as testing
307-
return testing
308-
309321
raise AttributeError("module {!r} has no attribute "
310322
"{!r}".format(__name__, attr))
311323

numpy/__init__.pyi

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ from numpy.lib.arraysetops import (
431431
isin as isin,
432432
)
433433

434-
from numpy.lib.arrayterator import (
435-
Arrayterator as Arrayterator,
436-
)
437-
438434
from numpy.lib.function_base import (
439435
select as select,
440436
piecewise as piecewise,
@@ -3152,8 +3148,6 @@ FPE_OVERFLOW: L[2]
31523148
FPE_UNDERFLOW: L[4]
31533149
FPE_INVALID: L[8]
31543150

3155-
FLOATING_POINT_SUPPORT: L[1]
3156-
31573151
little_endian: Final[bool]
31583152
True_: Final[bool_]
31593153
False_: Final[bool_]

numpy/core/_type_aliases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _set_up_aliases():
183183
pass
184184

185185
# Additional aliases in sctypeDict that should not be exposed as attributes
186-
attrs_to_remove = ['ulong']
186+
attrs_to_remove = ['ulong', 'long', 'unicode']
187187

188188
for t in attrs_to_remove:
189189
try:

numpy/core/numeric.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@
5252
'isclose', 'isscalar', 'binary_repr', 'base_repr', 'ones',
5353
'identity', 'allclose', 'compare_chararrays', 'putmask',
5454
'flatnonzero', 'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN',
55-
'False_', 'True_', 'bitwise_not', 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS',
56-
'BUFSIZE', 'ALLOW_THREADS', 'full', 'full_like',
57-
'matmul', 'shares_memory', 'may_share_memory', 'MAY_SHARE_BOUNDS',
58-
'MAY_SHARE_EXACT', '_get_promotion_state', '_set_promotion_state']
55+
'False_', 'True_', 'bitwise_not', 'full', 'full_like',
56+
'matmul', 'shares_memory', 'may_share_memory',
57+
'_get_promotion_state', '_set_promotion_state']
5958

6059

6160
def _zeros_like_dispatcher(a, dtype=None, order=None, subok=None, shape=None):

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val)
758758
"must be one of 'clip', 'raise', or 'wrap'");
759759
}
760760
else {
761-
/* For users passing `np.RAISE`, `np.WRAP`, `np.CLIP` */
761+
/* For users passing `RAISE`, `WRAP`, `CLIP` */
762762
int number = PyArray_PyIntAsInt(object);
763763
if (error_converting(number)) {
764764
goto fail;
@@ -769,7 +769,8 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val)
769769
}
770770
else {
771771
PyErr_Format(PyExc_ValueError,
772-
"integer clipmode must be np.RAISE, np.WRAP, or np.CLIP");
772+
"integer clipmode must be RAISE, WRAP, or CLIP "
773+
"from 'numpy.core.multiarray'");
773774
}
774775
}
775776
return NPY_SUCCEED;

numpy/core/tests/test_conversion_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import numpy as np
1010
import numpy.core._multiarray_tests as mt
11+
from numpy.core.multiarray import CLIP, WRAP, RAISE
1112
from numpy.testing import assert_warns, IS_PYPY
1213

1314

@@ -156,9 +157,9 @@ def test_valid(self):
156157
self._check('raise', 'NPY_RAISE')
157158

158159
# integer values allowed here
159-
assert self.conv(np.CLIP) == 'NPY_CLIP'
160-
assert self.conv(np.WRAP) == 'NPY_WRAP'
161-
assert self.conv(np.RAISE) == 'NPY_RAISE'
160+
assert self.conv(CLIP) == 'NPY_CLIP'
161+
assert self.conv(WRAP) == 'NPY_WRAP'
162+
assert self.conv(RAISE) == 'NPY_RAISE'
162163

163164

164165
class TestCastingConverter(StringConverterTestCase):

numpy/core/umath.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
_extobj_contextvar)
1717

1818
__all__ = [
19-
'_UFUNC_API', 'FLOATING_POINT_SUPPORT',
20-
'FPE_DIVIDEBYZERO', 'FPE_INVALID', 'FPE_OVERFLOW', 'FPE_UNDERFLOW',
21-
'NAN', 'NINF', 'NZERO', 'PINF', 'PZERO', 'UFUNC_BUFSIZE_DEFAULT',
22-
'UFUNC_PYVALS_NAME', '_add_newdoc_ufunc', 'absolute', 'add',
19+
'absolute', 'add',
2320
'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh',
2421
'bitwise_and', 'bitwise_or', 'bitwise_xor', 'cbrt', 'ceil', 'conj',
2522
'conjugate', 'copysign', 'cos', 'cosh', 'deg2rad', 'degrees', 'divide',

numpy/lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
from ._version import *
5858
from numpy.core._multiarray_umath import tracemalloc_domain
5959

60-
__all__ = ['emath', 'tracemalloc_domain', 'Arrayterator']
60+
__all__ = ['emath', 'tracemalloc_domain']
6161
__all__ += type_check.__all__
6262
__all__ += index_tricks.__all__
6363
__all__ += function_base.__all__

numpy/lib/arrayterator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Arrayterator:
6666
Examples
6767
--------
6868
>>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
69-
>>> a_itor = np.lib.Arrayterator(a, 2)
69+
>>> a_itor = np.lib.arrayterator.Arrayterator(a, 2)
7070
>>> a_itor.shape
7171
(3, 4, 5, 6)
7272
@@ -139,17 +139,18 @@ def flat(self):
139139
A 1-D flat iterator for Arrayterator objects.
140140
141141
This iterator returns elements of the array to be iterated over in
142-
`~lib.Arrayterator` one by one. It is similar to `flatiter`.
142+
`~lib.arrayterator.Arrayterator` one by one.
143+
It is similar to `flatiter`.
143144
144145
See Also
145146
--------
146-
lib.Arrayterator
147+
lib.arrayterator.Arrayterator
147148
flatiter
148149
149150
Examples
150151
--------
151152
>>> a = np.arange(3 * 4 * 5 * 6).reshape(3, 4, 5, 6)
152-
>>> a_itor = np.lib.Arrayterator(a, 2)
153+
>>> a_itor = np.lib.arrayterator.Arrayterator(a, 2)
153154
154155
>>> for subarr in a_itor.flat:
155156
... if not subarr:

numpy/lib/function_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
'rot90', 'extract', 'place', 'vectorize', 'asarray_chkfinite', 'average',
4545
'bincount', 'digitize', 'cov', 'corrcoef',
4646
'msort', 'median', 'sinc', 'hamming', 'hanning', 'bartlett',
47-
'blackman', 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',
48-
'meshgrid', 'delete', 'insert', 'append', 'interp', 'add_newdoc_ufunc',
47+
'blackman', 'kaiser', 'trapz', 'i0',
48+
'meshgrid', 'delete', 'insert', 'append', 'interp',
4949
'quantile'
5050
]
5151

numpy/tests/test_public_api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def test_numpy_namespace():
3434
# None of these objects are publicly documented to be part of the main
3535
# NumPy namespace (some are useful though, others need to be cleaned up)
3636
undocumented = {
37-
'_add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc',
38-
'add_docstring': 'numpy.core._multiarray_umath.add_docstring',
39-
'add_newdoc': 'numpy.core.function_base.add_newdoc',
40-
'add_newdoc_ufunc': 'numpy.core._multiarray_umath._add_newdoc_ufunc',
4137
'byte_bounds': 'numpy.lib.utils.byte_bounds',
4238
'compare_chararrays': 'numpy.core._multiarray_umath.compare_chararrays',
4339
'deprecate': 'numpy.lib.utils.deprecate',

numpy/typing/tests/data/fail/arrayterator.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ from typing import Any
22
import numpy as np
33

44
AR_i8: np.ndarray[Any, np.dtype[np.int64]]
5-
ar_iter = np.lib.Arrayterator(AR_i8)
5+
ar_iter = np.lib.arrayterator.Arrayterator(AR_i8)
66

7-
np.lib.Arrayterator(np.int64()) # E: incompatible type
7+
np.lib.arrayterator.Arrayterator(np.int64()) # E: incompatible type
88
ar_iter.shape = (10, 5) # E: is read-only
99
ar_iter[None] # E: Invalid index type
1010
ar_iter[None, 1] # E: Invalid index type

numpy/typing/tests/data/fail/constants.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ import numpy as np
22

33
np.Inf = np.Inf # E: Cannot assign to final
44
np.little_endian = np.little_endian # E: Cannot assign to final
5-
np.UFUNC_PYVALS_NAME = "bob" # E: Incompatible types
6-
np.CLIP = 2 # E: Incompatible types

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
AR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.arange(10)
8-
ar_iter = np.lib.Arrayterator(AR_i8)
8+
ar_iter = np.lib.arrayterator.Arrayterator(AR_i8)
99

1010
ar_iter.var
1111
ar_iter.buf_size

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ reveal_type(np.infty) # E: float
1515
reveal_type(np.nan) # E: float
1616
reveal_type(np.pi) # E: float
1717

18-
reveal_type(np.CLIP) # E: Literal[0]
1918
reveal_type(np.FLOATING_POINT_SUPPORT) # E: Literal[1]
2019
reveal_type(np.FPE_DIVIDEBYZERO) # E: Literal[1]
2120
reveal_type(np.FPE_INVALID) # E: Literal[8]
@@ -24,8 +23,6 @@ reveal_type(np.FPE_UNDERFLOW) # E: Literal[4]
2423
reveal_type(np.MAXDIMS) # E: Literal[32]
2524
reveal_type(np.MAY_SHARE_BOUNDS) # E: Literal[0]
2625
reveal_type(np.MAY_SHARE_EXACT) # E: Literal[-1]
27-
reveal_type(np.RAISE) # E: Literal[2]
28-
reveal_type(np.WRAP) # E: Literal[1]
2926
reveal_type(np.tracemalloc_domain) # E: Literal[389047]
3027

3128
reveal_type(np.little_endian) # E: bool

0 commit comments

Comments
 (0)
0