From 0855709348d2f1d8a84e1205fc414af1fbbe712b Mon Sep 17 00:00:00 2001 From: Andrei Batomunkuev Date: Wed, 24 Nov 2021 01:47:41 +0000 Subject: BUG: Fixed output overriding in numpy.info(), so that it correctly displays in Google Colab. Closes#20423 --- numpy/lib/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 1df2ab09b..96f64ac3e 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -429,7 +429,7 @@ def _makenamedict(module='numpy'): return thedict, dictlist -def _info(obj, output=sys.stdout): +def _info(obj, output=None): """Provide information about ndarray obj. Parameters @@ -455,6 +455,9 @@ def _info(obj, output=sys.stdout): strides = obj.strides endian = obj.dtype.byteorder + if output is None: + output = sys.stdout + print("class: ", nm, file=output) print("shape: ", obj.shape, file=output) print("strides: ", strides, file=output) @@ -481,7 +484,7 @@ def _info(obj, output=sys.stdout): @set_module('numpy') -def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): +def info(object=None, maxwidth=76, output=None, toplevel='numpy'): """ Get help information for a function, class, or module. @@ -541,6 +544,9 @@ def info(object=None, maxwidth=76, output=sys.stdout, toplevel='numpy'): elif hasattr(object, '_ppimport_attr'): object = object._ppimport_attr + if output is None: + output = sys.stdout + if object is None: info(info) elif isinstance(object, ndarray): -- cgit v1.2.1 From 504a477a637894309ed23d954554ce1ad8bf609e Mon Sep 17 00:00:00 2001 From: Andrei Batomunkuev Date: Wed, 24 Nov 2021 02:17:14 +0000 Subject: Fixed python docstring in info() --- numpy/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 96f64ac3e..cd0e3f3cf 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -499,7 +499,7 @@ def info(object=None, maxwidth=76, output=None, toplevel='numpy'): Printing width. output : file like object, optional File like object that the output is written to, default is - ``stdout``. The object has to be opened in 'w' or 'a' mode. + ``None``. The object has to be opened in 'w' or 'a' mode. toplevel : str, optional Start search at this level. -- cgit v1.2.1 From 860c66c19866050bbf25f7f675ecff3ab88398e2 Mon Sep 17 00:00:00 2001 From: Andrei Batomunkuev Date: Wed, 24 Nov 2021 20:08:48 +0000 Subject: BUG: Fixed docstring of numpy.info() --- numpy/lib/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index cd0e3f3cf..c74ee127d 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -499,7 +499,8 @@ def info(object=None, maxwidth=76, output=None, toplevel='numpy'): Printing width. output : file like object, optional File like object that the output is written to, default is - ``None``. The object has to be opened in 'w' or 'a' mode. + ``None``, in which case ``sys.stdout`` will be used. + The object has to be opened in 'w' or 'a' mode. toplevel : str, optional Start search at this level. -- cgit v1.2.1