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

Skip to content

Commit c85323c

Browse files
committed
[DEP] Remove numpy.who
1 parent f0befec commit c85323c

File tree

5 files changed

+2
-133
lines changed

5 files changed

+2
-133
lines changed

numpy/core/tests/test_deprecations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,12 @@ class TestLibImports(_DeprecationTestCase):
778778
# Deprecated in Numpy 1.26.0, 2023-09
779779
def test_lib_functions_deprecation_call(self):
780780
from numpy import (
781-
byte_bounds, safe_eval, who, recfromcsv, recfromtxt,
781+
byte_bounds, safe_eval, recfromcsv, recfromtxt,
782782
disp, get_array_wrap, maximum_sctype
783783
)
784784
from numpy.lib.tests.test_io import TextIO
785785

786786
self.assert_deprecated(lambda: safe_eval("None"))
787-
self.assert_deprecated(lambda: who())
788787

789788
data_gen = lambda: TextIO('A,B\n0,1\n2,3')
790789
kwargs = dict(delimiter=",", missing_values="N/A", names=True)

numpy/lib/tests/test_regression.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,6 @@ def test_void_coercion(self):
158158
x = np.zeros((1,), dt)
159159
assert_(np.r_[x, x].dtype == dt)
160160

161-
@pytest.mark.filterwarnings("ignore:.*who.*:DeprecationWarning")
162-
def test_who_with_0dim_array(self):
163-
# ticket #1243
164-
import os
165-
import sys
166-
167-
oldstdout = sys.stdout
168-
sys.stdout = open(os.devnull, 'w')
169-
try:
170-
try:
171-
np.who({'foo': np.array(1)})
172-
except Exception:
173-
raise AssertionError("ticket #1243")
174-
finally:
175-
sys.stdout.close()
176-
sys.stdout = oldstdout
177-
178161
def test_include_dirs(self):
179162
# As a sanity check, just test that get_include
180163
# includes something reasonable. Somewhat

numpy/lib/utils.py

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
__all__ = [
1616
'issubclass_', 'issubsctype', 'issubdtype', 'deprecate',
17-
'deprecate_with_doc', 'get_include', 'info', 'who',
17+
'deprecate_with_doc', 'get_include', 'info',
1818
'byte_bounds', 'safe_eval', 'show_runtime'
1919
]
2020

@@ -345,116 +345,6 @@ def byte_bounds(a):
345345
return a_low, a_high
346346

347347

348-
#-----------------------------------------------------------------------------
349-
# Function for output and information on the variables used.
350-
#-----------------------------------------------------------------------------
351-
352-
353-
def who(vardict=None):
354-
"""
355-
Print the NumPy arrays in the given dictionary.
356-
357-
.. deprecated:: 2.0
358-
359-
If there is no dictionary passed in or `vardict` is None then returns
360-
NumPy arrays in the globals() dictionary (all NumPy arrays in the
361-
namespace).
362-
363-
Parameters
364-
----------
365-
vardict : dict, optional
366-
A dictionary possibly containing ndarrays. Default is globals().
367-
368-
Returns
369-
-------
370-
out : None
371-
Returns 'None'.
372-
373-
Notes
374-
-----
375-
Prints out the name, shape, bytes and type of all of the ndarrays
376-
present in `vardict`.
377-
378-
Examples
379-
--------
380-
>>> a = np.arange(10)
381-
>>> b = np.ones(20)
382-
>>> np.who()
383-
Name Shape Bytes Type
384-
===========================================================
385-
a 10 80 int64
386-
b 20 160 float64
387-
Upper bound on total bytes = 240
388-
389-
>>> d = {'x': np.arange(2.0), 'y': np.arange(3.0), 'txt': 'Some str',
390-
... 'idx':5}
391-
>>> np.who(d)
392-
Name Shape Bytes Type
393-
===========================================================
394-
x 2 16 float64
395-
y 3 24 float64
396-
Upper bound on total bytes = 40
397-
398-
"""
399-
400-
# Deprecated in NumPy 2.0, 2023-07-11
401-
warnings.warn(
402-
"`who` is deprecated. "
403-
"(deprecated in NumPy 2.0)",
404-
DeprecationWarning,
405-
stacklevel=2
406-
)
407-
408-
if vardict is None:
409-
frame = sys._getframe().f_back
410-
vardict = frame.f_globals
411-
sta = []
412-
cache = {}
413-
for name in vardict.keys():
414-
if isinstance(vardict[name], ndarray):
415-
var = vardict[name]
416-
idv = id(var)
417-
if idv in cache.keys():
418-
namestr = name + " (%s)" % cache[idv]
419-
original = 0
420-
else:
421-
cache[idv] = name
422-
namestr = name
423-
original = 1
424-
shapestr = " x ".join(map(str, var.shape))
425-
bytestr = str(var.nbytes)
426-
sta.append([namestr, shapestr, bytestr, var.dtype.name,
427-
original])
428-
429-
maxname = 0
430-
maxshape = 0
431-
maxbyte = 0
432-
totalbytes = 0
433-
for val in sta:
434-
if maxname < len(val[0]):
435-
maxname = len(val[0])
436-
if maxshape < len(val[1]):
437-
maxshape = len(val[1])
438-
if maxbyte < len(val[2]):
439-
maxbyte = len(val[2])
440-
if val[4]:
441-
totalbytes += int(val[2])
442-
443-
if len(sta) > 0:
444-
sp1 = max(10, maxname)
445-
sp2 = max(10, maxshape)
446-
sp3 = max(10, maxbyte)
447-
prval = "Name %s Shape %s Bytes %s Type" % (sp1*' ', sp2*' ', sp3*' ')
448-
print(prval + "\n" + "="*(len(prval)+5) + "\n")
449-
450-
for val in sta:
451-
print("%s %s %s %s %s %s %s" % (val[0], ' '*(sp1-len(val[0])+4),
452-
val[1], ' '*(sp2-len(val[1])+5),
453-
val[2], ' '*(sp3-len(val[2])+5),
454-
val[3]))
455-
print("\nUpper bound on total bytes = %d" % totalbytes)
456-
return
457-
458348
#-----------------------------------------------------------------------------
459349

460350

numpy/lib/utils.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ def deprecate_with_doc(msg: None | str) -> _Deprecate: ...
6363
# `byte_bounds`. This concerns `"strides"` and `"data"`.
6464
def byte_bounds(a: generic | ndarray[Any, Any]) -> tuple[int, int]: ...
6565

66-
def who(vardict: None | Mapping[str, ndarray[Any, Any]] = ...) -> None: ...
67-
6866
def info(
6967
object: object = ...,
7068
maxwidth: int = ...,

numpy/tests/test_public_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def test_numpy_namespace():
5252
'set_string_function': 'numpy.core.arrayprint.set_string_function',
5353
'show_config': 'numpy.__config__.show',
5454
'show_runtime': 'numpy.lib.utils.show_runtime',
55-
'who': 'numpy.lib.utils.who',
5655
}
5756
# We override dir to not show these members
5857
allowlist = undocumented

0 commit comments

Comments
 (0)