8000 Merge pull request #24567 from mtsokol/lib-pad-setops-ufunc-utils-nam… · numpy/numpy@39bc1b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39bc1b1

Browse files
authored
Merge pull request #24567 from mtsokol/lib-pad-setops-ufunc-utils-namespace
API: Update `arraypad`,`arraysetops`, `ufunclike` and `utils` namespaces in `np.lib`
2 parents ff5dce9 + 08e086c commit 39bc1b1

26 files changed

+97
-157
lines changed

benchmarks/benchmarks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
def show_cpu_features():
6-
from numpy.lib.utils import _opt_info
6+
from numpy.lib._utils_impl import _opt_info
77
info = _opt_info()
88
info = "NumPy CPU features: " + (info if info else 'nothing enabled')
99
# ASV wrapping stdout & stderr, so we assume having a tty here

doc/source/reference/routines.set.rst

Lines changed: 0 add 1E79 itions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ Set routines
33

44
. F438 . currentmodule:: numpy
55

6-
.. autosummary::
7-
:toctree: generated/
8-
9-
lib.arraysetops
10-
116
Making proper sets
127
------------------
138
.. autosummary::

numpy/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,18 @@
185185
from .lib import (
186186
DataSource, apply_along_axis, apply_over_axes,
187187
array_split, broadcast_arrays, broadcast_shapes,
188-
broadcast_to, byte_bounds, c_, column_stack, diag_indices,
188+
broadcast_to, c_, column_stack, diag_indices,
189189
diag_indices_from, dsplit, dstack,
190-
ediff1d, emath, expand_dims, fill_diagonal, fix,
190+
emath, expand_dims, fill_diagonal,
191191
fromregex, get_array_wrap, genfromtxt,
192-
get_include, hsplit, in1d, index_exp, info, intersect1d,
193-
isin, isneginf, ix_, kron, load, loadtxt,
192+
hsplit, index_exp, ix_, kron, load, loadtxt,
194193
mgrid, ndenumerate, ndindex, ogrid,
195-
packbits, pad, poly, poly1d, polyadd, polyder,
194+
packbits, poly, poly1d, polyadd, polyder,
196195
polydiv, polyfit, polyint, polymul, polysub, polyval,
197196
put_along_axis, r_, ravel_multi_index,
198-
roots, row_stack, s_, save, savetxt, savez, savez_compressed,
199-
setdiff1d, setxor1d, show_runtime, split,
200-
take_along_axis, tile, union1d, unique, unpackbits,
201-
unravel_index, vsplit, isposinf
197+
roots, row_stack, s_, save, savetxt, savez,
198+
savez_compressed, split, take_along_axis, tile,
199+
unpackbits, unravel_index, vsplit
202200
)
203201
from .lib._histograms_impl import (
204202
histogram, histogram_bin_edges, histogramdd
@@ -224,6 +222,14 @@
224222
iscomplexobj, isrealobj, imag, iscomplex, isreal, nan_to_num, real,
225223
real_if_close, typename, mintypecode, common_type
226224
)
225+
from .lib._arraysetops_impl import (
226+
ediff1d, in1d, intersect1d, isin, setdiff1d, setxor1d, union1d, unique
227+
)
228+
from .lib._ufunclike_impl import fix, isneginf, isposinf
229+
from .lib._arraypad_impl import pad
230+
from .lib._utils_impl import (
231+
byte_bounds, show_runtime, get_include, info
232+
)
227233
from . import matrixlib as _mat
228234
from .matrixlib import (
229235
asmatrix, bmat, matrix
@@ -289,6 +295,10 @@
289295
set(lib._function_base_impl.__all__) |
290296
set(lib._twodim_base_impl.__all__) |
291297
set(lib._type_check_impl.__all__) |
298+
set(lib._arraysetops_impl.__all__) |
299+
set(lib._ufunclike_impl.__all__) |
300+
set(lib._arraypad_impl.__all__) |
301+
set(lib._utils_impl.__all__) |
292302
{"show_config", "__version__"}
293303
)
294304

numpy/__init__.pyi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ from numpy.lib import (
397397
emath as emath,
398398
)
399399

400-
from numpy.lib.arraypad import (
400+
from numpy.lib._arraypad_impl import (
401401
pad as pad,
402402
)
403403

404-
from numpy.lib.arraysetops import (
404+
from numpy.lib._arraysetops_impl import (
405405
ediff1d as ediff1d,
406406
intersect1d as intersect1d,
407407
setxor1d as setxor1d,
@@ -575,17 +575,15 @@ from numpy.lib._type_check_impl import (
575575
common_type as common_type,
576576
)
577577

578-
from numpy.lib.ufunclike import (
578+
from numpy.lib._ufunclike_impl import (
579579
fix as fix,
580580
isposinf as isposinf,
581581
isneginf as isneginf,
582582
)
583583

584-
from numpy.lib.utils import (
585-
issubdtype as issubdtype,
584+
from numpy.lib._utils_impl import (
586585
get_include as get_include,
587586
info as info,
588-
source as source,
589587
byte_bounds as byte_bounds,
590588
show_runtime as show_runtime,
591589
)

numpy/_pytesttester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _show_numpy_info():
3939
print("NumPy version %s" % np.__version__)
4040
relaxed_strides = np.ones((10, 1), order="C").flags.f_contiguous
4141
print("NumPy relaxed strides checking option:", relaxed_strides)
42-
info = np.lib.utils._opt_info()
42+
info = np.lib._utils_impl._opt_info()
4343
print("NumPy CPU features: ", (info if info else 'nothing enabled'))
4444

4545

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def test_deprecated_np_lib_math(self):
753753
class TestLibImports(_DeprecationTestCase):
754754
# Deprecated in Numpy 1.26.0, 2023-09
755755
def test_lib_functions_deprecation_call(self):
756-
from numpy.lib.utils import safe_eval
756+
from numpy.lib._utils_impl import safe_eval
757757
from numpy.lib.npyio import recfromcsv, recfromtxt
758758
from numpy.lib._function_base_impl import disp
759759
from numpy.lib.shape_base import get_array_wrap

numpy/lib/__init__.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,22 @@
2626
from . import shape_base
2727
from . import stride_tricks
2828
from . import _twodim_base_impl
29-
from . import ufunclike
29+
from . import _ufunclike_impl
3030
from . import _histograms_impl
3131
from . import polynomial
32-
from . import utils
33-
from . import arraysetops
32+
from . import _utils_impl
33+
from . import _arraysetops_impl
3434
from . import npyio
3535
from . import arrayterator
36-
from . import arraypad
36+
from . import _arraypad_impl
3737
from . import _version
3838

3939
from .index_tricks import *
4040
from .shape_base import *
4141
from .stride_tricks import *
42-
from .ufunclike import *
43-
4442
from .polynomial import *
45-
from .utils import *
46-
from .arraysetops import *
4743
from .npyio import *
4844
from .arrayterator import Arrayterator
49-
from .arraypad import *
5045
from ._version import *
5146
from numpy.core._multiarray_umath import add_docstring, tracemalloc_domain
5247
from numpy.core.function_base import add_newdoc
@@ -56,11 +51,7 @@
5651
__all__ += index_tricks.__all__
5752
__all__ += shape_base.__all__
5853
__all__ += stride_tricks.__all__
59-
__all__ += ufunclike.__all__
60-
__all__ += arraypad.__all__
6154
__all__ += polynomial.__all__
62-
__all__ += utils.__all__
63-
__all__ += arraysetops.__all__
6455
__all__ += npyio.__all__
6556

6657
from numpy._pytesttester import PytestTester
@@ -78,7 +69,15 @@ def __getattr__(attr):
7869
"`math` module (Deprecated Numpy 1.25). Replace usages of "
7970
"`numpy.lib.math` with `math`", DeprecationWarning, stacklevel=2)
8071
return math
72+
elif attr in (
73+
"histograms", "type_check", "nanfunctions", "function_base",
74+
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base"
75+
):
76+
raise AttributeError(
77+
f"`np.lib.{attr}` is now private. If you are using a public "
78+
"function, it should be available in the main numpy namespace, "
79+
"otherwise check the NumPy 2.0 migration guide."
80+
)
8181
else:
8282
raise AttributeError("module {!r} has no attribute "
8383
"{!r}".format(__name__, attr))
84-

numpy/lib/__init__.pyi

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@ from numpy.lib._version import (
2121
NumpyVersion as NumpyVersion,
2222
)
2323

24-
from numpy.lib.arraypad import (
25-
pad as pad,
26-
)
27-
28-
from numpy.lib.arraysetops import (
29-
ediff1d as ediff1d,
30-
intersect1d as intersect1d,
31-
setxor1d as setxor1d,
32-
union1d as union1d,
33-
setdiff1d as setdiff1d,
34-
unique as unique,
35-
in1d as in1d,
36-
isin as isin,
37-
)
38-
3924
from numpy.lib.arrayterator import (
4025
Arrayterator as Arrayterator,
4126
)
@@ -110,19 +95,6 @@ from numpy.lib.stride_tricks import (
11095
broadcast_shapes as broadcast_shapes,
11196
)
11297

113-
from numpy.lib.ufunclike import (
114-
fix as fix,
115-
isposinf as isposinf,
116-
isneginf as isneginf,
117-
)
118-
119-
from numpy.lib.utils import (
120-
get_include as get_include,
121-
info as info,
122-
byte_bounds as byte_bounds,
123-
show_runtime as show_runtime,
124-
)
125-
12698
from numpy.core.multiarray import (
12799
add_docstring as add_docstring,
128100
tracemalloc_domain as tracemalloc_domain,
File renamed without changes.
File renamed without changes.

numpy/lib/arraysetops.py renamed to numpy/lib/_arraysetops_impl.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def unique(ar, return_index=False, return_inverse=False,
195195
196196
See Also
197197
--------
198-
numpy.lib.arraysetops : Module with a number of other functions for
199-
performing set operations on arrays.
200198
repeat : Repeat elements of an array.
201199
202200
Notes
@@ -404,12 +402,6 @@ def intersect1d(ar1, ar2, assume_unique=False, return_indices=False):
404402
The indices of the first occurrences of the common values in `ar2`.
405403
Only provided if `return_indices` is True.
406404
407-
408-
See Also
409-
--------
410-
numpy.lib.arraysetops : Module with a number of other functions for
411-
performing set operations on arrays.
412-
413405
Examples
414406
--------
415407
>>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1])
@@ -577,8 +569,6 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
577569
--------
578570
isin : Version of this function that preserves the
579571
shape of ar1.
580-
numpy.lib.arraysetops : Module with a number of other functions for
581-
performing set operations on arrays.
582572
583573
Notes
584574
-----
@@ -818,8 +808,6 @@ def isin(element, test_elements, assume_unique=False, invert=False, *,
818808
See Also
819809
--------
820810
in1d : Flattened version of this function.
821-
numpy.lib.arraysetops : Module with a number of other functions for
822-
performing set operations on arrays.
823811
824812
Notes
825813
-----
@@ -914,11 +902,6 @@ def union1d(ar1, ar2):
914902
union1d : ndarray
915903
Unique, sorted union of the input arrays.
916904
917-
See Also
918-
--------
919-
numpy.lib.arraysetops : Module with a number of other functions for
920-
performing set operations on arrays.
921-
922905
Examples
923906
--------
924907
>>> np.union1d([-1, 0, 1], [-2, 0, 2])
@@ -961,11 +944,6 @@ def setdiff1d(ar1, ar2, assume_unique=False):
961944
is sorted when `assume_unique=False`, but otherwise only sorted
962945
if the input is sorted.
963946
964-
See Also
965-
--------
966-
numpy.lib.arraysetops : Module with a number of other functions for
967-
performing set operations on arrays.
968-
969947
Examples
970948
--------
971949
>>> a = np.array([1, 2, 3, 2, 4, 1])
File renamed without changes.

numpy/lib/_function_base_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3901,7 +3901,7 @@ def _median(a, axis=None, out=None, overwrite_input=False):
39013901
rout = mean(part[indexer], axis=axis, out=out)
39023902
if supports_nans and sz > 0:
39033903
# If nans are possible, warn and replace by nans like mean would.
3904-
rout = np.lib.utils._median_nancheck(part, rout, axis)
3904+
rout = np.lib._utils_impl._median_nancheck(part, rout, axis)
39053905

39063906
return rout
39073907

numpy/lib/_type_check_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy.core.numeric as _nx
1313
from numpy.core.numeric import asarray, asanyarray, isnan, zeros
1414
from numpy.core import overrides, getlimits
15-
from .ufunclike import isneginf, isposinf
15+
from ._ufunclike_impl import isneginf, isposinf
1616

1717

1818
array_function_dispatch = functools.partial(
File renamed without changes.
File renamed without changes.

numpy/lib/utils.py renamed to numpy/lib/_utils_impl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
]
1717

1818

19+
@set_module('numpy')
1920
def show_runtime():
2021
"""
2122
Print information about various resources in the system
@@ -69,6 +70,7 @@ def show_runtime():
6970
pprint(config_found)
7071

7172

73+
@set_module('numpy')
7274
def get_include():
7375
"""
7476
Return the directory that contains the NumPy \\*.h header files.
@@ -290,6 +292,7 @@ def deprecate_with_doc(msg):
290292
#--------------------------------------------
291293

292294

295+
@set_module('numpy')
293296
def byte_bounds(a):
294297
"""
295298
Returns pointers to the end-points of an array.
File renamed without changes.

numpy/lib/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
import warnings
168168

169169
import numpy
170-
from numpy.lib.utils import drop_metadata
170+
from numpy.lib._utils_impl import drop_metadata
171171

172172

173173
__all__ = []

numpy/lib/tests/test_arraypad.py

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

66
import numpy as np
77
from numpy.testing import assert_array_equal, assert_allclose, assert_equal
8-
from numpy.lib.arraypad import _as_pairs
8+
from numpy.lib._arraypad_impl import _as_pairs
99

1010

1111
_numeric_dtypes = (
@@ -628,7 +628,7 @@ def test_check_constant_odd_pad_amount(self):
628628

629629
def test_check_constant_pad_2d(self):
630630
arr = np.arange(4).reshape(2, 2)
631-
test = np.lib.pad(arr, ((1, 2), (1, 3)), mode='constant',
631+
test = np.pad(arr, ((1, 2), (1, 3)), mode='constant',
632632
constant_values=((1, 2), (3, 4)))
633633
expected = np.array(
634634
[[3, 1, 1, 4, 4, 4],

numpy/lib/tests/test_arraysetops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"""
44
import numpy as np
55

6-
from numpy.testing import (assert_array_equal, assert_equal,
7-
assert_raises, assert_raises_regex)
8-
from numpy.lib.arraysetops import (
6+
from numpy import (
97
ediff1d, intersect1d, setxor1d, union1d, setdiff1d, unique, in1d, isin
108
)
119
from numpy.exceptions import AxisError
10+
from numpy.testing import (assert_array_equal, assert_equal,
11+
assert_raises, assert_raises_regex)
1212
import pytest
1313

1414

numpy/lib/tests/test_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ def test_metadata_dtype(dt, fail):
10221022
else:
10231023
arr2 = np.load(buf)
10241024
# BUG: assert_array_equal does not check metadata
1025-
from numpy.lib.utils import drop_metadata
1025+
from numpy.lib._utils_impl import drop_metadata
10261026
assert_array_equal(arr, arr2)
10271027
assert drop_metadata(arr.dtype) is not arr.dtype
10281028
assert drop_metadata(arr2.dtype) is arr2.dtype

0 commit comments

Comments
 (0)
0