diff options
author | Shota Kawabuchi <shota.kawabuchi+Github@gmail.com> | 2016-10-22 17:08:28 +0900 |
---|---|---|
committer | Shota Kawabuchi <shota.kawabuchi+Github@gmail.com> | 2016-10-29 22:54:33 +0900 |
commit | a6c2184c0dbc70b9a57fce21e4f769d313021261 (patch) | |
tree | a98c44a0ac54c44e911dfd0b1ba045f7eef768a4 /numpy/core/arrayprint.py | |
parent | 2a4dd999c82276d00ef96d0d5839ff8b1f8a8871 (diff) | |
download | numpy-a6c2184c0dbc70b9a57fce21e4f769d313021261.tar.gz |
BUG: Fix array2string for structured array scalars
PR #8160 added format function for structured arrays.
But it is not applied for structured array scalars.
Closes #8172
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 1d93a0c0b..ce0c6244e 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -316,18 +316,6 @@ def _get_format_function(data, precision, suppress_small, formatter): def _array2string(a, max_line_width, precision, suppress_small, separator=' ', prefix="", formatter=None): - if max_line_width is None: - max_line_width = _line_width - - if precision is None: - precision = _float_output_precision - - if suppress_small is None: - suppress_small = _float_output_suppress_small - - if formatter is None: - formatter = _formatter - if a.size > _summaryThreshold: summary_insert = "..., " data = _leading_trailing(a) @@ -458,11 +446,27 @@ def array2string(a, max_line_width=None, precision=None, """ + if max_line_width is None: + max_line_width = _line_width + + if precision is None: + precision = _float_output_precision + + if suppress_small is None: + suppress_small = _float_output_suppress_small + + if formatter is None: + formatter = _formatter + if a.shape == (): x = a.item() - if isinstance(x, tuple): - x = _convert_arrays(x) - lst = style(x) + if a.dtype.fields is not None: + arr = asarray([x], dtype=a.dtype) + format_function = _get_format_function( + arr, precision, suppress_small, formatter) + lst = format_function(arr[0]) + else: + lst = style(x) elif reduce(product, a.shape) == 0: # treat as a null array if any of shape elements == 0 lst = "[]" @@ -471,6 +475,7 @@ def array2string(a, max_line_width=None, precision=None, separator, prefix, formatter=formatter) return lst + def _extendLine(s, line, word, max_line_len, next_line_prefix): if len(line.rstrip()) + len(word.rstrip()) >= max_line_len: s += line.rstrip() + "\n" |