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

Skip to content

Commit 1a082eb

Browse files
committed
Apply review comments
1 parent 4e55295 commit 1a082eb

File tree

13 files changed

+46
-35
lines changed

13 files changed

+46
-35
lines changed

doc/source/reference/routines.io.rst

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

84-
DataSource
84+
lib.npyio.DataSource
8585

8686
Binary format description
8787
-------------------------
8888
.. autosummary::
8989
:toctree: generated/
9090

9191
lib.format
92+
93+
Object wrappers
94+
---------------
95+
.. autosummary::
96+
:toctree: generated/
97+
98+
lib.npyio.BagObj

numpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
polyfit, poly1d, roots
238238
)
239239
from .lib._npyio_impl import (
240-
DataSource, savetxt, loadtxt, genfromtxt, load, save, savez, packbits,
240+
savetxt, loadtxt, genfromtxt, load, save, savez, packbits,
241241
savez_compressed, unpackbits, fromregex
242242
)
243243
from . import matrixlib as _mat

numpy/__init__.pyi

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,25 +3297,6 @@ class ndindex:
32973297
def __iter__(self: _T) -> _T: ...
32983298
def __next__(self) -> _Shape: ...
32993299

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

numpy/_expired_attrs_2_0.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@
6565
"`scalar_types` argument, use `numpy.result_type` and pass the "
6666
"Python values `0`, `0.0`, or `0j`.",
6767
"round_": "Use `np.round` instead.",
68-
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead."
68+
"nbytes": "Use `np.dtype(<dtype>).itemsize` instead.",
69+
"DataSource": "It's still available as `np.lib.npyio.DataSource`.",
6970
}

numpy/lib/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def __getattr__(attr):
6666
return math
6767
elif attr in (
6868
"histograms", "type_check", "nanfunctions", "function_base",
69-
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base"
69+
"arraypad", "arraysetops", "ufunclike", "utils", "twodim_base",
70+
"polynomial"
7071
):
7172
raise AttributeError(
7273
f"`np.lib.{attr}` is now private. If you are using a public "

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')

numpy/lib/_npyio_impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
__all__ = [
29-
'savetxt', 'loadtxt', 'genfromtxt', 'load', 'save', 'savez', 'DataSource',
29+
'savetxt', 'loadtxt', 'genfromtxt', 'load', 'save', 'savez',
3030
'savez_compressed', 'packbits', 'unpackbits', 'fromregex'
3131
]
3232

@@ -35,6 +35,7 @@
3535
overrides.array_function_dispatch, module='numpy')
3636

3737

38+
@set_module('numpy.lib.npyio')
3839
class BagObj:
3940
"""
4041
BagObj(obj)
@@ -99,6 +100,7 @@ def zipfile_factory(file, *args, **kwargs):
99100
return zipfile.ZipFile(file, *args, **kwargs)
100101

101102

103+
@set_module('numpy.lib.npyio')
102104
class NpzFile(Mapping):
103105
"""
104106
NpzFile(fid)

numpy/lib/_npyio_impl.pyi

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from typing import (
1515
)
1616

1717
from numpy import (
18-
DataSource as DataSource,
1918
ndarray,
2019
recarray,
2120
dtype,
@@ -101,6 +100,25 @@ class NpzFile(Mapping[str, NDArray[Any]]):
101100
def __contains__(self, key: str) -> bool: ...
102101
def __repr__(self) -> str: ...
103102

103+
class DataSource:
104+
def __init__(
105+
self,
106+
destpath: None | str | os.PathLike[str] = ...,
107+
) -> None: ...
108+
def __del__(self) -> None: ...
109+
def abspath(self, path: str) -> str: ...
110+
def exists(self, path: str) -> bool: ...
111+
112+
# Whether the file-object is opened in string or bytes mode (by default)
113+
# depends on the file-extension of `path`
114+
def open(
115+
self,
116+
path: str,
117+
mode: str = ...,
118+
encoding: None | str = ...,
119+
newline: None | str = ...,
120+
) -> IO[Any]: ...
121+
104122
# NOTE: Returns a `NpzFile` if file is a zip file;
105123
# returns an `ndarray`/`memmap` otherwise
106124
def load(

numpy/lib/npyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from ._npyio_impl import BagObj, NpzFile
1+
from ._npyio_impl import BagObj, DataSource, NpzFile

numpy/lib/npyio.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from numpy.lib._npyio_impl import (
22
BagObj as BagObj,
3+
DataSource as DataSource,
34
NpzFile as NpzFile,
45
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from pathlib import Path
22
import numpy as np
33

44
path: Path
5-
d1: np.DataSource
5+
d1: np.lib.npyio.DataSource
66

77
d1.abspath(path) # E: incompatible type
88
d1.abspath(b"...") # E: incompatible type

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import numpy as np
44
path1: Path
55
path2: str
66

7-
d1 = np.DataSource(path1)
8-
d2 = np.DataSource(path2)
9-
d3 = np.DataSource(None)
7+
d1 = np.lib.npyio.DataSource(path1)
8+
d2 = np.lib.npyio.DataSource(path2)
9+
d3 = np.lib.npyio.DataSource(None)
1010

1111
reveal_type(d1.abspath("...")) # E: str
1212
reveal_type(d2.abspath("...")) # E: str

tools/refguide_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
# cases where NumPy docstrings import things from other 3'rd party libs:
9797
'numpy.core.from_dlpack': None,
9898
# remote / local file IO with DataSource is problematic in doctest:
99-
'numpy.lib.DataSource': None,
99+
'numpy.lib.npyio.DataSource': None,
100100
'numpy.lib.Repository': None,
101101
}
102102

0 commit comments

Comments
 (0)