Skip to content

Commit 3746939

Browse files
committed
DOC: override inherited Mapping docstrings in NpzFile
1 parent 5dbf807 commit 3746939

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

numpy/lib/_npyio_impl.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,34 @@ def __repr__(self):
278278
array_names += "..."
279279
return f"NpzFile {filename!r} with keys: {array_names}"
280280

281+
# Work around problems with the docstrings in the Mapping methods
282+
# They contain a `->`, which confuses the type annotation interpretations
283+
# of sphinx-docs. See gh-25964
284+
285+
def get(self, key, default=None, /):
286+
"""
287+
D.get(k,[,d]) returns D[k] if k in D, else d. d defaults to None.
288+
"""
289+
return dict.get(self, key, default)
290+
291+
def items(self):
292+
"""
293+
D.items() returns a set-like object providing a view on the items
294+
"""
295+
return dict.items(self)
296+
297+
def keys(self):
298+
"""
299+
D.keys() returns a set-like object providing a view on the keys
300+
"""
301+
return dict.keys(self)
302+
303+
def values(self):
304+
"""
305+
D.values() returns a set-like object providing a view on the values
306+
"""
307+
return dict.values(self)
308+
281309

282310
@set_module('numpy')
283311
def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True,
@@ -487,9 +515,9 @@ def save(file, arr, allow_pickle=True, fix_imports=True):
487515
arr : array_like
488516
Array data to be saved.
489517
allow_pickle : bool, optional
490-
Allow saving object arrays using Python pickles. Reasons for
518+
Allow saving object arrays using Python pickles. Reasons for
491519
disallowing pickles include security (loading pickled data can execute
492-
arbitrary code) and portability (pickled objects may not be loadable
520+
arbitrary code) and portability (pickled objects may not be loadable
493521
on different Python installations, for example if the stored objects
494522
require libraries that are not available, and not all pickled data is
495523
compatible between Python 2 and Python 3).
@@ -1814,10 +1842,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
18141842
.. versionadded:: 1.10.0
18151843
encoding : str, optional
18161844
Encoding used to decode the inputfile. Does not apply when `fname`
1817-
is a file object. The special value 'bytes' enables backward
1845+
is a file object. The special value 'bytes' enables backward
18181846
compatibility workarounds that ensure that you receive byte arrays
1819-
when possible and passes latin1 encoded strings to converters.
1820-
Override this value to receive unicode arrays and pass strings
1847+
when possible and passes latin1 encoded strings to converters.
1848+
Override this value to receive unicode arrays and pass strings
18211849
as input to converters. If set to None the system default is used.
18221850
The default value is 'bytes'.
18231851
@@ -1854,7 +1882,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
18541882
* Individual values are not stripped of spaces by default.
18551883
When using a custom converter, make sure the function does remove spaces.
18561884
* Custom converters may receive unexpected values due to dtype
1857-
discovery.
1885+
discovery.
18581886
18591887
References
18601888
----------
@@ -2127,7 +2155,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
21272155
except ValueError:
21282156
# We couldn't find it: the name must have been dropped
21292157
continue
2130-
# Redefine the key if it's a column number
2158+
# Redefine the key if it's a column number
21312159
# and usecols is defined
21322160
if usecols:
21332161
try:
@@ -2161,23 +2189,23 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
21612189
if len(dtype_flat) > 1:
21622190
# Flexible type : get a converter from each dtype
21632191
zipit = zip(dtype_flat, missing_values, filling_values)
2164-
converters = [StringConverter(dt,
2192+
converters = [StringConverter(dt,
21652193
locked=True,
2166-
missing_values=miss,
2194+
missing_values=miss,
21672195
default=fill)
21682196
for (dt, miss, fill) in zipit]
21692197
else:
21702198
# Set to a default converter (but w/ different missing values)
21712199
zipit = zip(missing_values, filling_values)
2172-
converters = [StringConverter(dtype,
2200+
converters = [StringConverter(dtype,
21732201
locked=True,
2174-
missing_values=miss,
2202+
missing_values=miss,
21752203
default=fill)
21762204
for (miss, fill) in zipit]
21772205
# Update the converters to use the user-defined ones
21782206
uc_update = []
21792207
for (j, conv) in user_converters.items():
2180-
# If the converter is specified by column names,
2208+
# If the converter is specified by column names,
21812209
# use the index instead
21822210
if _is_string_like(j):
21832211
try:
@@ -2201,8 +2229,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
22012229
if conv is bytes:
22022230
user_conv = asbytes
22032231
elif byte_converters:
2204-
# Converters may use decode to workaround numpy's old
2205-
# behavior, so encode the string again before passing
2232+
# Converters may use decode to workaround numpy's old
2233+
# behavior, so encode the string again before passing
22062234
# to the user converter.
22072235
def tobytes_first(x, conv):
22082236
if type(x) is bytes:
@@ -2338,7 +2366,7 @@ def tobytes_first(x, conv):
23382366
"argument is deprecated. Set the encoding, use None for the "
23392367
"system default.",
23402368
np.exceptions.VisibleDeprecationWarning, stacklevel=2)
2341-
2369+
23422370
def encode_unicode_cols(row_tup):
23432371
row = list(row_tup)
23442372
for i in strcolidx:

0 commit comments

Comments
 (0)