summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-01-11 13:22:00 -0500
committerGitHub <noreply@github.com>2018-01-11 13:22:00 -0500
commit36bc343495ef7aa45f7d8540040cb9f577ef22fa (patch)
tree5e01586710cf94c7dc68655a0e001993de599325 /numpy/core/arrayprint.py
parent10a0ba58d8b4321bc2f5dc846ee8ff5d5733bbe4 (diff)
parent087619a78dedb3f491654d727d279c1dcb4fb480 (diff)
downloadnumpy-36bc343495ef7aa45f7d8540040cb9f577ef22fa.tar.gz
Merge pull request #10367 from eric-wieser/fix-10366
BUG: add missing paren and remove quotes from repr of fieldless struct
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 18ba23624..6af73e6d7 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -1177,7 +1177,6 @@ class SubArrayFormat(object):
class StructureFormat(object):
def __init__(self, format_functions):
self.format_functions = format_functions
- self.num_fields = len(format_functions)
@classmethod
def from_data(cls, data, **options):
@@ -1194,11 +1193,14 @@ class StructureFormat(object):
return cls(format_functions)
def __call__(self, x):
- s = "("
- for field, format_function in zip(x, self.format_functions):
- s += format_function(field) + ", "
- return (s[:-2] if 1 < self.num_fields else s[:-1]) + ")"
-
+ str_fields = [
+ format_function(field)
+ for field, format_function in zip(x, self.format_functions)
+ ]
+ if len(str_fields) == 1:
+ return "({},)".format(str_fields[0])
+ else:
+ return "({})".format(", ".join(str_fields))
def _void_scalar_repr(x):
"""
@@ -1258,7 +1260,7 @@ def dtype_short_repr(dtype):
"""
# handle these separately so they don't give garbage like str256
if issubclass(dtype.type, flexible):
- if dtype.names:
+ if dtype.names is not None:
return "%s" % str(dtype)
else:
return "'%s'" % str(dtype)