diff options
author | Allan Haldane <allan.haldane@gmail.com> | 2017-09-07 12:06:41 -0400 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-09-26 23:54:26 -0700 |
commit | 0f63efa619a1f6dc0a2673be026c042807e31807 (patch) | |
tree | 6cb92d10c1a809022f25dea33196422489e9f3f8 /numpy/core/arrayprint.py | |
parent | 7666d14a5b5c2d94ddb064db83e85d8b8656c7d5 (diff) | |
download | numpy-0f63efa619a1f6dc0a2673be026c042807e31807.tar.gz |
BUG: remove voidtype-repr recursion in scalartypes.c/arrayprint.py
Fixes #9345
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 31 |
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) |