Thanks to visit codestin.com
Credit goes to github.com

Skip to content

API: Update lib.polynomial and lib.npyio namespaces #24578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/reference/routines.io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Data sources
.. autosummary::
:toctree: generated/

DataSource
lib.npyio.DataSource

Binary format description
-------------------------
Expand Down
18 changes: 12 additions & 6 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,9 @@

from . import lib
from .lib import (
DataSource, c_, diag_indices, diag_indices_from, emath,
fromregex, genfromtxt, index_exp, ix_, load, loadtxt,
c_, diag_indices, diag_indices_from, emath, index_exp, ix_,
mgrid, ndenumerate, ndindex, ogrid, fill_diagonal,
packbits, poly, poly1d, polyadd, polyder,
polydiv, polyfit, polyint, polymul, polysub, polyval,
r_, ravel_multi_index, roots, s_, save, savetxt, savez,
savez_compressed, unpackbits, unravel_index
r_, ravel_multi_index, s_, unravel_index
)
from .lib._histograms_impl import (
histogram, histogram_bin_edges, histogramdd
Expand Down Expand Up @@ -231,6 +227,14 @@
from .lib._stride_tricks_impl import (
broadcast_arrays, broadcast_shapes, broadcast_to
)
from .lib._polynomial_impl import (
poly, polyint, polyder, polyadd, polysub, polymul, polydiv, polyval,
polyfit, poly1d, roots
)
from .lib._npyio_impl import (
savetxt, loadtxt, genfromtxt, load, save, savez, packbits,
savez_compressed, unpackbits, fromregex
)
from . import matrixlib as _mat
from .matrixlib import (
asmatrix, bmat, matrix
Expand Down Expand Up @@ -302,6 +306,8 @@
set(lib._arraypad_impl.__all__) |
set(lib._utils_impl.__all__) |
set(lib._stride_tricks_impl.__all__) |
set(lib._polynomial_impl.__all__) |
set(lib._npyio_impl.__all__) |
{"show_config", "__version__"}
)

Expand Down
23 changes: 2 additions & 21 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ from numpy.lib._nanfunctions_impl import (
nanquantile as nanquantile,
)

from numpy.lib.npyio import (
from numpy.lib._npyio_impl import (
savetxt as savetxt,
loadtxt as loadtxt,
genfromtxt as genfromtxt,
Expand All @@ -504,7 +504,7 @@ from numpy.lib.npyio import (
fromregex as fromregex,
)

from numpy.lib.polynomial import (
from numpy.lib._polynomial_impl import (
poly as poly,
roots as roots,
polyint as polyint,
Expand Down Expand Up @@ -3296,25 +3296,6 @@ class ndindex:
def __iter__(self: _T) -> _T: ...
def __next__(self) -> _Shape: ...

class DataSource:
def __init__(
self,
destpath: None | str | os.PathLike[str] = ...,
) -> None: ...
def __del__(self) -> None: ...
def abspath(self, path: str) -> str: ...
def exists(self, path: str) -> bool: ...

# Whether the file-object is opened in string or bytes mode (by default)
# depends on the file-extension of `path`
def open(
self,
path: str,
mode: str = ...,
encoding: None | str = ...,
newline: None | str = ...,
) -> IO[Any]: ...

# TODO: The type of each `__next__` and `iters` return-type depends
# on the length and dtype of `args`; we can't describe this behavior yet
# as we lack variadics (PEP 646).
Expand Down
1 change: 1 addition & 0 deletions numpy/_expired_attrs_2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@
"round_": "Use `np.round` instead.",
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead.",
"get_array_wrap": "",
"DataSource": "It's still available as `np.lib.npyio.DataSource`.",
}
2 changes: 1 addition & 1 deletion numpy/core/tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ class TestLibImports(_DeprecationTestCase):
# Deprecated in Numpy 1.26.0, 2023-09
def test_lib_functions_deprecation_call(self):
from numpy.lib._utils_impl import safe_eval
from numpy.lib.npyio import recfromcsv, recfromtxt
from numpy.lib._npyio_impl import recfromcsv, recfromtxt
from numpy.lib._function_base_impl import disp
from numpy.lib._shape_base_impl import get_array_wrap
from numpy.core.numerictypes import maximum_sctype
Expand Down
9 changes: 3 additions & 6 deletions numpy/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
from . import _twodim_base_impl
from . import _ufunclike_impl
from . import _histograms_impl
from . import polynomial
from . import _utils_impl
from . import _arraysetops_impl
from . import _polynomial_impl
from . import _npyio_impl
from . import npyio
from . import arrayterator
from . import _arraypad_impl
from . import _version

from .index_tricks import *
from .polynomial import *
from .npyio import *
from .arrayterator import Arrayterator
from ._version import *
from numpy.core._multiarray_umath import add_docstring, tracemalloc_domain
Expand All @@ -48,8 +47,6 @@

__all__ = ['emath']
__all__ += index_tricks.__all__
__all__ += polynomial.__all__
__all__ += npyio.__all__

from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
Expand All @@ -69,7 +66,7 @@ def __getattr__(attr):
elif attr in (
"histograms", "type_check", "nanfunctions", "function_base",
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base",
"shape_base"
"shape_base", "polynomial"
):
raise AttributeError(
f"`np.lib.{attr}` is now private. If you are using a public "
Expand Down
31 changes: 1 addition & 30 deletions numpy/lib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from numpy.lib import (
mixins as mixins,
scimath as scimath,
stride_tricks as stride_tricks,
npyio as npyio,
)

from numpy.lib._version import (
Expand All @@ -40,36 +41,6 @@ from numpy.lib.index_tricks import (
diag_indices_from as diag_indices_from,
)

from numpy.lib.npyio import (
savetxt as savetxt,
loadtxt as loadtxt,
genfromtxt as genfromtxt,
recfromtxt as recfromtxt,
recfromcsv as recfromcsv,
load as load,
save as save,
savez as savez,
savez_compressed as savez_compressed,
packbits as packbits,
unpackbits as unpackbits,
fromregex as fromregex,
DataSource as DataSource,
)

from numpy.lib.polynomial import (
poly as poly,
roots as roots,
polyint as polyint,
polyder as polyder,
polyadd as polyadd,
polysub as polysub,
polymul as polymul,
polydiv as polydiv,
polyval as polyval,
polyfit as polyfit,
poly1d as poly1d,
)

from numpy.core.multiarray import (
add_docstring as add_docstring,
tracemalloc_domain as tracemalloc_domain,
Expand Down
8 changes: 4 additions & 4 deletions numpy/lib/_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def open(path, mode='r', destpath=os.curdir, encoding=None, newline=None):
return ds.open(path, mode, encoding=encoding, newline=newline)


@set_module('numpy')
@set_module('numpy.lib.npyio')
class DataSource:
"""
DataSource(destpath='.')
Expand All @@ -216,7 +216,7 @@ class DataSource:
URLs require a scheme string (``http://``) to be used, without it they
will fail::

>>> repos = np.DataSource()
>>> repos = np.lib.npyio.DataSource()
>>> repos.exists('www.google.com/index.html')
False
>>> repos.exists('http://www.google.com/index.html')
Expand All @@ -228,13 +228,13 @@ class DataSource:
--------
::

>>> ds = np.DataSource('/home/guido')
>>> ds = np.lib.npyio.DataSource('/home/guido')
>>> urlname = 'http://www.google.com/'
>>> gfile = ds.open('http://www.google.com/')
>>> ds.abspath(urlname)
'/home/guido/www.google.com/index.html'

>>> ds = np.DataSource(None) # use with temporary file
>>> ds = np.lib.npyio.DataSource(None) # use with temporary file
>>> ds.open('/home/guido/foobar.txt')
<open file '/home/guido.foobar.txt', mode 'r' at 0x91d4430>
>>> ds.abspath('/home/guido/foobar.txt')
Expand Down
Loading