10000 API: Update `lib.polynomial` and `lib.npyio` namespaces (#24578) · numpy/numpy@63d9da8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63d9da8

Browse files
authored
API: Update lib.polynomial and lib.npyio namespaces (#24578)
1 parent 99c1d5f commit 63d9da8

20 files changed

+2943
-2954
lines changed

doc/source/reference/routines.io.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Data sources
8181
.. autosummary::
8282
:toctree: generated/
8383

84-
DataSource
84+
lib.npyio.DataSource
8585

8686
Binary format description
8787
-------------------------

numpy/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,9 @@
183183

184184
from . import lib
185185
from .lib import (
186-
DataSource, c_, diag_indices, diag_indices_from, emath,
187-
fromregex, genfromtxt, index_exp, ix_, load, loadtxt,
186+
c_, diag_indices, diag_indices_from, emath, index_exp, ix_,
188187
mgrid, ndenumerate, ndindex, ogrid, fill_diagonal,
189-
packbits, poly, poly1d, polyadd, polyder,
190-
polydiv, polyfit, polyint, polymul, polysub, polyval,
191-
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
192-
savez_compressed, unpackbits, unravel_index
188+
r_, ravel_multi_index, s_, unravel_index
193189
)
194190
from .lib._histograms_impl import (
195191
histogram, histogram_bin_edges, histogramdd
@@ -231,6 +227,14 @@
231227
from .lib._stride_tricks_impl import (
232228
broadcast_arrays, broadcast_shapes, broadcast_to
233229
)
230+
from .lib._polynomial_impl import (
231+
poly, polyint, polyder, polyadd, polysub, polymul, polydiv, polyval,
232+
polyfit, poly1d, roots
233+
)
234+
from .lib._npyio_impl import (
235+
savetxt, loadtxt, genfromtxt, load, save, savez, packbits,
236+
savez_compressed, unpackbits, fromregex
237+
)
234238
from . import matrixlib as _mat
235239
from .matrixlib import (
236240
asmatrix, bmat, matrix
@@ -302,6 +306,8 @@
302306
set(lib._arraypad_impl.__all__) |
303307
set(lib._utils_impl.__all__) |
304308
set(lib._stride_tricks_impl.__all__) |
309+
set(lib._polynomial_impl.__all__) |
310+
set(lib._npyio_impl.__all__) |
305311
{"show_config", "__version__"}
306312
)
307313

numpy/__init__.pyi

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ from numpy.lib._nanfunctions_impl import (
489489
nanquantile as nanquantile,
490490
)
491491

492-
from numpy.lib.npyio import (
492+
from numpy.lib._npyio_impl import (
493493
savetxt as savetxt,
494494
loadtxt as loadtxt,
495495
genfromtxt as genfromtxt,
@@ -504,7 +504,7 @@ from numpy.lib.npyio import (
504504
fromregex as fromregex,
505505
)
506506

507-
from numpy.lib.polynomial import (
507+
from numpy.lib._polynomial_impl import (
508508
poly as poly,
509509
roots as roots,
510510
polyint as polyint,
@@ -3296,25 +3296,6 @@ class ndindex:
32963296
def __iter__(self: _T) -> _T: ...
32973297
def __next__(self) -> _Shape: ...
32983298

3299-
class DataSource:
3300-
def __init__(
3301-
self,
3302-
destpath: None | str | os.PathLike[str] = ...,
3303-
) -> None: ...
3304-
def __del__(self) -> None: ...
3305-
def abspath(self, path: str) -> str: ...
3306-
def exists(self, path: str) -> bool: ...
3307-
3308-
# Whether the file-object is opened in string or bytes mode (by default)
3309-
# depends on the file-extension of `path`
3310-
def open(
3311-
self,
3312-
path: str,
3313-
mode: str = ...,
3314-
encoding: None | str = ...,
3315-
newline: None | str = ...,
3316-
) -> IO[Any]: ...
3317-
33183299
# TODO: The type of each `__next__` and `iters` return-type depends
33193300
# on the length and dtype of `args`; we can't describe this behavior yet
33203301
# as we lack variadics (PEP 646).

numpy/_expired_attrs_2_0.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@
6767
"round_": "Use `np.round` instead.",
6868
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead.",
6969
"get_array_wrap": "",
70+
"DataSource": "It's still available as `np.lib.npyio.DataSource`.",
7071
}

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ class TestLibImports(_DeprecationTestCase):
750750
# Deprecated in Numpy 1.26.0, 2023-09
751751
def test_lib_functions_deprecation_call(self):
752752
from numpy.lib._utils_impl import safe_eval
753-
from numpy.lib.npyio import recfromcsv, recfromtxt
753+
from numpy.lib._npyio_impl import recfromcsv, recfromtxt
754754
from numpy.lib._function_base_impl import disp
755755
from numpy.lib._shape_base_impl import get_array_wrap
756756
from numpy.core.numerictypes import maximum_sctype

numpy/lib/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@
2929
from . import _twodim_base_impl
3030
from . import _ufunclike_impl
3131
from . import _histograms_impl
32-
from . import polynomial
3332
from . import _utils_impl
3433
from . import _arraysetops_impl
34+
from . import _polynomial_impl
35+
from . import _npyio_impl
3536
from . import npyio
3637
from . import arrayterator
3738
from . import _arraypad_impl
3839
from . import _version
3940

4041
from .index_tricks import *
41-
from .polynomial import *
42-
from .npyio import *
4342
from .arrayterator import Arrayterator
4443
from ._version import *
4544
from numpy.core._multiarray_umath import add_docstring, tracemalloc_domain
@@ -48,8 +47,6 @@
4847

4948
__all__ = ['emath']
5049
__all__ += index_tricks.__all__
51-
__all__ += polynomial.__all__
52-
__all__ += npyio.__all__
5350

5451
from numpy._pytesttester import PytestTester
5552
test = PytestTester(__name__)
@@ -69,7 +66,7 @@ def __getattr__(attr):
6966
elif attr in (
7067
"histograms", "type_check", "nanfunctions", "function_base",
7168
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base",
72-
"shape_base"
69+
"shape_base", "polynomial"
7370
):
7471
raise AttributeError(
7572
f"`np.lib.{attr}` is now private. If you are using a public "

numpy/lib/__init__.pyi

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ from numpy.lib import (
1515
mixins as mixins,
1616
scimath as scimath,
1717
stride_tricks as stride_tricks,
18+
npyio as npyio,
1819
)
1920

2021
from numpy.lib._version import (
@@ -40,36 +41,6 @@ from numpy.lib.index_tricks import (
4041
diag_indices_from as diag_indices_from,
4142
)
4243

43-
from numpy.lib.npyio import (
44-
savetxt as savetxt,
45-
loadtxt as loadtxt,
46-
genfromtxt as genfromtxt,
47-
recfromtxt as recfromtxt,
48-
recfromcsv as recfromcsv,
49-
load as load,
50-
save as save,
51-
savez as savez,
52-
savez_compressed as savez_compressed,
53-
packbits as packbits,
54-
unpackbits as unpackbits,
55-
fromregex as fromregex,
56-
DataSource as DataSource,
57-
)
58-
59-
from numpy.lib.polynomial import (
60-
poly as poly,
61-
roots as roots,
62-
polyint as polyint,
63-
polyder as polyder,
64-
polyadd as polyadd,
65-
polysub as polysub,
66-
polymul as polymul,
67-
polydiv as polydiv,
68-
polyval as polyval,
69-
polyfit as polyfit,
70-
poly1d as poly1d,
71-
)
72-
7344
from numpy.core.multiarray import (
7445
add_docstring as add_docstring,
7546
tracemalloc_domain as tracemalloc_domain,

numpy/lib/_datasource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def open(path, mode='r', destpath=os.curdir, encoding=None, newline=None):
192192
return ds.open(path, mode, encoding=encoding, newline=newline)
193193

194194

195-
@set_module('numpy')
195+
@set_module('numpy.lib.npyio')
196196
class DataSource:
197197
"""
198198
DataSource(destpath='.')
@@ -216,7 +216,7 @@ class DataSource:
216216
URLs require a scheme string (``http://``) to be used, without it they
217217
will fail::
218218
219-
>>> repos = np.DataSource()
219+
>>> repos = np.lib.npyio.DataSource()
220220
>>> repos.exists('www.google.com/index.html')
221221
False
222222
>>> repos.exists('http://www.google.com/index.html')
@@ -228,13 +228,13 @@ class DataSource:
228228
--------
229229
::
230230
231-
>>> ds = np.DataSource('/home/guido')
231+
>>> ds = np.lib.npyio.DataSource('/home/guido')
232232
>>> urlname = 'http://www.google.com/'
233233
>>> gfile = ds.open('http://www.google.com/')
234234
>>> ds.abspath(urlname)
235235
'/home/guido/www.google.com/index.html'
236236
237-
>>> ds = np.DataSource(None) # use with temporary file
237+
>>> ds = np.lib.npyio.DataSource(None) # use with temporary file
238238
>>> ds.open('/home/guido/foobar.txt')
239239
<open file '/home/guido.foobar.txt', mode 'r' at 0x91d4430>
240240
>>> ds.abspath('/home/guido/foobar.txt')

0 commit comments

Comments
 (0)
0