summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorAllan Haldane <ealloc@gmail.com>2017-09-28 17:51:35 +0200
committerGitHub <noreply@github.com>2017-09-28 17:51:35 +0200
commitcea77c21cd0907afc0093b7301d7824d73f7c740 (patch)
treeaff42687b117d5bf0fa89a32c79675987ea8d048 /numpy/core/arrayprint.py
parenteb5dd4128e8323f5c4af089d2fea85e6159dd739 (diff)
parent0f63efa619a1f6dc0a2673be026c042807e31807 (diff)
downloadnumpy-cea77c21cd0907afc0093b7301d7824d73f7c740.tar.gz
Merge pull request #9784 from eric-wieser/fix-void-recursion
BUG: remove voidtype-repr recursion in scalartypes.c/arrayprint.py
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index e0da9f81e..e1df556ef 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -309,13 +309,7 @@ def _get_format_function(data, **options):
"""
dtype_ = data.dtype
if dtype_.fields is not None:
- format_functions = []
- for field_name in dtype_.names:
- format_function = _get_format_function(data[field_name], **options)
- if dtype_[field_name].shape != ():
- format_function = SubArrayFormat(format_function)
- format_functions.append(format_function)
- return StructureFormat(format_functions)
+ return StructureFormat.from_data(data, **options)
dtypeobj = dtype_.type
formatdict = _get_formatdict(data, **options)
@@ -873,6 +867,20 @@ class StructureFormat(object):
self.format_functions = format_functions
self.num_fields = len(format_functions)
+ @classmethod
+ def from_data(cls, data, **options):
+ """
+ This is a second way to initialize StructureFormat, using the raw data
+ as input. Added to avoid changing the signature of __init__.
+ """
+ format_functions = []
+ for field_name in data.dtype.names:
+ format_function = _get_format_function(data[field_name], **options)
+ if data.dtype[field_name].shape != ():
+ format_function = SubArrayFormat(format_function)
+ format_functions.append(format_function)
+ return cls(format_functions)
+
def __call__(self, x):
s = "("
for field, format_function in zip(x, self.format_functions):
@@ -880,6 +888,15 @@ class StructureFormat(object):
return (s[:-2] if 1 < self.num_fields else s[:-1]) + ")"
+def _void_scalar_repr(x):
+ """
+ Implements the repr for structured-void scalars. It is called from the
+ scalartypes.c.src code, and is placed here because it uses the elementwise
+ formatters defined above.
+ """
+ return StructureFormat.from_data(array(x), **_format_options)(x)
+
+
_typelessdata = [int_, float_, complex_]
if issubclass(intc, int):
_typelessdata.append(intc)