summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2019-10-15 09:44:15 -0700
committerGitHub <noreply@github.com>2019-10-15 09:44:15 -0700
commitb89caf6dd1341032fbffbe0888097a018037af00 (patch)
tree46056076194f4608eaaea0877f5ab0ab1b6ca0db /numpy/core/arrayprint.py
parentc7f532e9acd1a2e2c7bd49f6355959511281c134 (diff)
parent7f1293f7100d47824c12281238ce42aeef69167c (diff)
downloadnumpy-b89caf6dd1341032fbffbe0888097a018037af00.tar.gz
Merge pull request #14368 from jdufresne/byteswarning
MAINT: Avoid BytesWarning in PyArray_DescrConverter()
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 233d139fd..8a7626d9d 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -1479,7 +1479,11 @@ def array_repr(arr, max_line_width=None, precision=None, suppress_small=None):
arr, max_line_width, precision, suppress_small)
-_guarded_str = _recursive_guard()(str)
+@_recursive_guard()
+def _guarded_repr_or_str(v):
+ if isinstance(v, bytes):
+ return repr(v)
+ return str(v)
def _array_str_implementation(
@@ -1497,7 +1501,7 @@ def _array_str_implementation(
# obtain a scalar and call str on it, avoiding problems for subclasses
# for which indexing with () returns a 0d instead of a scalar by using
# ndarray's getindex. Also guard against recursive 0d object arrays.
- return _guarded_str(np.ndarray.__getitem__(a, ()))
+ return _guarded_repr_or_str(np.ndarray.__getitem__(a, ()))
return array2string(a, max_line_width, precision, suppress_small, ' ', "")