Skip to content

Commit

Permalink
Merge pull request #19615 from rossbar/rm-deprecated-npyio-fns
Browse files Browse the repository at this point in the history
MAINT: Proposal to expire three deprecated functions in numpy.lib.npyio
  • Loading branch information
charris committed Aug 6, 2021
2 parents 2f52098 + 29fcb7f commit 261a769
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 100 deletions.
8 changes: 8 additions & 0 deletions doc/release/upcoming_changes/19615.expired.rst
@@ -0,0 +1,8 @@
Expired deprecations for ``loads``, ``ndfromtxt``, and ``mafromtxt`` in npyio
-----------------------------------------------------------------------------

``numpy.loads`` was deprecated in v1.15, with the recommendation that users
use `pickle.loads` instead.
``ndfromtxt`` and ``mafromtxt`` were both deprecated in v1.17 - users should
use `numpy.genfromtxt` instead with the appropriate value for the
``usemask`` parameter.
1 change: 0 additions & 1 deletion numpy/__init__.pyi
Expand Up @@ -516,7 +516,6 @@ from numpy.lib.npyio import (
recfromtxt as recfromtxt,
recfromcsv as recfromcsv,
load as load,
loads as loads,
save as save,
savez as savez,
savez_compressed as savez_compressed,
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/_add_newdocs.py
Expand Up @@ -3252,7 +3252,7 @@
a.dumps()
Returns the pickle of the array as a string.
pickle.loads or numpy.loads will convert the string back to an array.
pickle.loads will convert the string back to an array.
Parameters
----------
Expand Down
1 change: 0 additions & 1 deletion numpy/lib/__init__.pyi
Expand Up @@ -130,7 +130,6 @@ from numpy.lib.npyio import (
recfromtxt as recfromtxt,
recfromcsv as recfromcsv,
load as load,
loads as loads,
save as save,
savez as savez,
savez_compressed as savez_compressed,
Expand Down
69 changes: 2 additions & 67 deletions numpy/lib/npyio.py
Expand Up @@ -26,18 +26,9 @@
)


@set_module('numpy')
def loads(*args, **kwargs):
# NumPy 1.15.0, 2017-12-10
warnings.warn(
"np.loads is deprecated, use pickle.loads instead",
DeprecationWarning, stacklevel=2)
return pickle.loads(*args, **kwargs)


__all__ = [
'savetxt', 'loadtxt', 'genfromtxt', 'ndfromtxt', 'mafromtxt',
'recfromtxt', 'recfromcsv', 'load', 'loads', 'save', 'savez',
'savetxt', 'loadtxt', 'genfromtxt',
'recfromtxt', 'recfromcsv', 'load', 'save', 'savez',
'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 'DataSource'
]

Expand Down Expand Up @@ -2313,62 +2304,6 @@ def encode_unicode_cols(row_tup):
)(genfromtxt)


def ndfromtxt(fname, **kwargs):
"""
Load ASCII data stored in a file and return it as a single array.
.. deprecated:: 1.17
ndfromtxt` is a deprecated alias of `genfromtxt` which
overwrites the ``usemask`` argument with `False` even when
explicitly called as ``ndfromtxt(..., usemask=True)``.
Use `genfromtxt` instead.
Parameters
----------
fname, kwargs : For a description of input parameters, see `genfromtxt`.
See Also
--------
numpy.genfromtxt : generic function.
"""
kwargs['usemask'] = False
# Numpy 1.17
warnings.warn(
"np.ndfromtxt is a deprecated alias of np.genfromtxt, "
"prefer the latter.",
DeprecationWarning, stacklevel=2)
return genfromtxt(fname, **kwargs)


def mafromtxt(fname, **kwargs):
"""
Load ASCII data stored in a text file and return a masked array.
.. deprecated:: 1.17
np.mafromtxt is a deprecated alias of `genfromtxt` which
overwrites the ``usemask`` argument with `True` even when
explicitly called as ``mafromtxt(..., usemask=False)``.
Use `genfromtxt` instead.
Parameters
----------
fname, kwargs : For a description of input parameters, see `genfromtxt`.
See Also
--------
numpy.genfromtxt : generic function to load ASCII data.
"""
kwargs['usemask'] = True
# Numpy 1.17
warnings.warn(
"np.mafromtxt is a deprecated alias of np.genfromtxt, "
"prefer the latter.",
DeprecationWarning, stacklevel=2)
return genfromtxt(fname, **kwargs)


def recfromtxt(fname, **kwargs):
"""
Load ASCII data from a file and return it in a record array.
Expand Down
6 changes: 0 additions & 6 deletions numpy/lib/npyio.pyi
Expand Up @@ -11,8 +11,6 @@ from numpy.core.multiarray import (

__all__: List[str]

def loads(*args, **kwargs): ...

class BagObj:
def __init__(self, obj): ...
def __getattribute__(self, key): ...
Expand Down Expand Up @@ -98,7 +96,3 @@ def genfromtxt(
): ...
def recfromtxt(fname, **kwargs): ...
def recfromcsv(fname, **kwargs): ...

# NOTE: Deprecated
# def ndfromtxt(fname, **kwargs): ...
# def mafromtxt(fname, **kwargs): ...
22 changes: 0 additions & 22 deletions numpy/lib/tests/test_io.py
Expand Up @@ -2503,28 +2503,6 @@ def test_genfromtxt(self):
data = np.genfromtxt(path)
assert_array_equal(a, data)

def test_ndfromtxt(self):
# Test outputting a standard ndarray
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
f.write(u'1 2\n3 4')

control = np.array([[1, 2], [3, 4]], dtype=int)
test = np.genfromtxt(path, dtype=int)
assert_array_equal(test, control)

def test_mafromtxt(self):
# From `test_fancy_dtype_alt` above
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
f.write(u'1,2,3.0\n4,5,6.0\n')

test = np.genfromtxt(path, delimiter=',', usemask=True)
control = ma.array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)])
assert_equal(test, control)

def test_recfromtxt(self):
with temppath(suffix='.txt') as path:
path = Path(path)
Expand Down
2 changes: 0 additions & 2 deletions numpy/tests/test_public_api.py
Expand Up @@ -45,8 +45,6 @@ def test_numpy_namespace():
'fastCopyAndTranspose': 'numpy.core._multiarray_umath._fastCopyAndTranspose',
'get_array_wrap': 'numpy.lib.shape_base.get_array_wrap',
'get_include': 'numpy.lib.utils.get_include',
'mafromtxt': 'numpy.lib.npyio.mafromtxt',
'ndfromtxt': 'numpy.lib.npyio.ndfromtxt',
'recfromcsv': 'numpy.lib.npyio.recfromcsv',
'recfromtxt': 'numpy.lib.npyio.recfromtxt',
'safe_eval': 'numpy.lib.utils.safe_eval',
Expand Down

0 comments on commit 261a769

Please sign in to comment.